0 votes
in Kotlin by
What is a data class in Kotlin?

1 Answer

0 votes
by

We frequently create classes whose main purpose is to hold data. In Kotlin, this is called a data class and is marked as data:

data class User(val name: String, val age: Int)

To ensure consistency and meaningful behavior of the generated code, data classes have to fulfill the following requirements:

  1. The primary constructor needs to have at least one parameter;
  2. All primary constructor parameters need to be marked as val or var;
  3. Data classes cannot be abstract, open, sealed or inner;

Related questions

0 votes
asked May 26, 2022 in Kotlin by Robin
0 votes
0 votes
asked May 26, 2022 in Kotlin by Robin
...