網上看到那麼一個問題,百度了一下沒有找到合適的答案。。。求大神解釋下。。。
JDK源碼的注釋說明的很清楚,如果重寫了equal方法,也應該重寫hashCode方法。看看源碼注釋吧,是非常好的文檔資料呢。
*Note that it is generally necessary to override the hashCode
* method whenever this method is overridden, so as to maintain the
* general contract for the hashCode method, which states
* that equal objects must have equal hash codes.