Sobes.tech
Junior — Middle

Can you list the key characteristics and features of data class in Kotlin?

sobes.tech AI

Answer from AI

A data class in Kotlin is a class designed to hold data with minimal boilerplate code. Key features:

  • equals(), hashCode(), toString(), as well as copy() and destructuring functions are automatically generated.
  • Main parameters are declared in the class constructor with the val or var keyword.
  • Used for simple data models where value semantics are important.

Example:

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

val user1 = User("Alice", 30)
val user2 = user1.copy(age = 31)
println(user1)  // User(name=Alice, age=30)
println(user2)  // User(name=Alice, age=31)
Can you list the key characteristics and features of… - sobes.tech