• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overriding hashcode

 
Aneek Banerjee
Ranch Hand
Posts: 61
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Matthew Brown
Bartender
Posts: 4565
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic