
HashCode and Equals method in Java object | Java Source World
HashCode and Equals method in Java object – A programmatic concept:
Object class provides two methods hashcode() and equals() to represent the identity of an object. It is a common convention that if one method is overridden then other should also be implemented.
Before explaining why, lets see what is the contract between these two methods hold. As per the Java API documentation:
Whenever hashcode is invoked on the same object more than once during an execution of a Java application, the hashcode() method must consistently return the same integer, provided no information used in equals() comparisons on the object is modified. This integer need not remain consistent from one execution of an application...