Equals() and hashCode()

Why should we implement equals() and hashCode() while using hastable?

Questions by naggeek

Showing Answers 1 - 3 of 3 Answers

inder_gwl

  • Sep 24th, 2009
 

You must override hashCode in every class that overrides equals(). Equal objects must have equal hash codes. In other words, If two objects are equal according to the equals (Object)method, then calling the hashCode method on each of the two objects must produce the same integer result. Overriding equals() method states the criteria for object equality and overriding hashCode() makes sure that Once two objects are equal, they always return the same hash code value.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions