In each class that overrides the Equals method, you must also overwrite the Hashcode method.
General conventions for Hashcode:
1 during the execution of a program, the Hashcode method must consistently return the same integer as long as the information used to compare the Equals method of the object has not been modified, and the same object is called multiple times.
2 If two objects are equal according to the Equals (object) method, the Hashcode method that calls either object in both objects must produce the same integer result.
3 If two objects are not equal according to the Equals (object) method, then calling the Hashcode method of any of these two objects does not necessarily produce a different integer result. The performance of the hash table can be improved by producing different integer results for unequal objects.
The key convention that is violated because there is no overwrite hashcode is 2nd: An equal object must have an equal hash code (hash code). Because the class does not overwrite the Hashcode method, two equal instances call the Hashcode method to return an integer that may not be equal.
A good hash function generates unequal hash codes for unequal objects. Ideally, the hash function should distribute the unequal instances of the collection evenly across all possible hash values. 31 can get better performance by replacing multiplication with shift and subtraction: 31*i== (i<<5)-I.
Resources
"Effective Java Chinese Version 2nd edition" 9th: Overwrite equals when always overwrite hashcode p39-43
Java objects overwrite equals when always overwrite Hashcode