Reputation: 303
I created a data class like shown in the pic . I created an object by passing appropriate parameters and I created another object , simultaneously assigning it to the first object. Later I changed my former object's parameters and checked weather these two objects are equal or not . To my surprise , the Boolean value came "TRUE" but isn't it that the parameters of two objects are different and it should return "FALSE" ?
Upvotes: 0
Views: 194
Reputation: 93571
user2 = user1
means "make user2
point at the same instance as what user1
is pointing at". So user2
and user1
are referencing the same instance.
If you want user2
to reference a distinct instance, you can create a copy for it:
val user2 = user1.copy()
Upvotes: 3