I have two objects lets say object 1 is t1 and object 2 is t2. I am assigning same integer value to this two objects,which is 10.Now I am confused how can I check if the both values are same for the object or not.And the second thing will the hash codes for these two objects will be same?(I believe not as ti.equals(t2) is giving me false).how can I check for the identical values here.
posted 3 years ago
When you're saying you're assigning the same integer value to two objects, what do you mean? Do you mean that the object has an integer member variable, and you're assigning the number to that?
If so, then you'd check for equality by comparing those member variables. And if you've got two different objects, and you haven't overridden hashCode(), then they will probably have different hash codes. If you have overridden hashCode(), then it depends on how you've done that.