equals()
(javadoc) must define an equivalence relation (it must be reflexive, symmetric, andtransitive). In addition, it must be consistent (if the objects are not modified, then it must keep returning the same value). Furthermore, o.equals(null)
must always return false.html
hashCode()
(javadoc) must also be consistent (if the object is not modified in terms of equals()
, it must keep returning the same value).java
The relation between the two methods is:api
Whenever
a.equals(b)
, thena.hashCode()
must be same asb.hashCode()
.oracle
equals 方法和hashcode方法的关系如上。当对象a等于对象b 那么他们的hashcode方法值也必定相同。flex