1, the existence of hashcode is mainly used to find the fast, such as Hashtable,hashmap, Hashcode is used in the hash storage structure to determine the storage address of the object;
2, if two objects are the same, is applicable to the Equals (Java.lang.Object) method, then the two objects must be the same hashcode;
3, if the object's Equals method is overridden, then the object's hashcode also try to rewrite, and produce hashcode used objects, must be consistent with the use of the Equals method, otherwise it will violate the above mentioned 2nd;
4, two objects of the same hashcode, does not necessarily mean that two objects are the same, that is not necessarily applicable to the Equals (Java.lang.Object) method, can only be explained that the two objects in the hash storage structure, such as Hashtable, they "stored in the same basket ”。
5. Hashcode is used for lookups, and equals is used to compare the equality of two objects.
6. General Agreement for the Hashcode method: If two objects are equal according to the Equals (object) method, then calling the Hashcode method on each object in two objects must produce the same integer result.
7, Equals method is unequal, and does not necessarily require hashcode nor want to wait; but generating different integer results for unequal objects can improve the performance of the hash table.
Java Learning (15): The Role of Hashcode