In each class that overrides the Equals method, you must also overwrite the Hashcode method. Failure to do so would violate Object.hashcode's general conventions, resulting in the class not working properly with all hash-based collections including HashMap,
HashSet, Hashtable.
Object specification:
During the execution of an application, the Hashcode method must return the same integer as long as the information of the object's Equals method is not modified so that the same object is called multiple times. During multiple executions of the same application, each execution of the returned integer can be inconsistent.
If two objects are equal according to the Equals method, then the Hashcode method that calls either object in the two objects must produce the same result
If two objects are not equal according to the Equals method, then calling the Hashcode method of any of these two objects does not necessarily produce a different integer result. However, it is possible to improve the performance of the hash list by producing distinct integer results for unequal objects.
Effectivejava (7) Overwrite equals when always overwrite Hashcode