Sobes.tech
Junior — Middle+

Checking equality of data class instances with mutable fields

livecode

Task condition

It is necessary to determine whether two objects of class Person, declared as a data class and created with the same value of the name property, will be considered equal when comparing person1 == person2, if after creation their mutable age field has different values.


data class Person(val name: String) {
    var age: Int = 0
}

val person1 = Person("John")
val person2 = Person("John")
person1.age = 10
person2.age = 20