Solution: Data class practice

data class Person(val name: String, val age: Int) fun main() { val person1 = Person("John", 30) println(person1) // Person(name=John, age=30) val person2 = person1.copy(name = "Jane") val person3 = Person("Jane", 30) println(person2 == person3) // true println(person1.hashCode()) // 71750739 println(person2.hashCode()) // 71339152 println(person3.hashCode()) // 71339152 val (name, age) = person2 println(name) // Jane println(age) // 30 }

Example solution in playground

data class Person(val name: String, val age: Int) fun main() { val person1 = Person("John", 30) println(person1) // Person(name=John, age=30) val person2 = person1.copy(name = "Jane") val person3 = Person("Jane", 30) println(person2 == person3) // true println(person1.hashCode()) // 71750739 println(person2.hashCode()) // 71339152 println(person3.hashCode()) // 71339152 val (name, age) = person2 println(name) // Jane println(age) // 30 }