Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: simplified opening paragraph

Wiki Markup
Classes that overrides the {{Object.equals()}} method must also override the {{Object.hashCode()}} method.  The Java API \[[API 2006|AA. Bibliography#API 06]\] class {{java.lang.Object}} documentationclass requires that

...

 any two objects

...

 that compare equal using the {{equals(Object)

...

}} method must produce the same integer result when the {{hashCode()}} method is invoked on the objects \[[API 2006|AA. Bibliography#API 06]\]. 

The equals() method is used to determine logical equivalence between object instances. Consequently, the hashCode() method must return the same value for all equivalent objects. Failure to follow this contract is a common source of defects.

...

Wiki Markup
This compliant solution overrides the {{hashCode()}} method so that it generates the same value for any two instances that are considered to be equal by the {{equals()}} method. Bloch discusses the recipe to generate such a hash function in good detail \[[Bloch 2008|AA. Bibliography#Bloch 08]\].

...