If two objects are equal according to the equals
method, their hashcodes must be equal as well. Otherwise, lookup in the hash table would fail.
Why we should Override hashcode() when overriding equals() method? [duplicate]
Question
Why we should always override hashCode()
method whenever we override equals()
method? As per my understanding they both seem to fulfill different purpose. hashCode()
method is used in hashtables to determine the equality of keys. However equals()
method is used to determine the equality of two objects.
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow