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