散列碼(hashcode)

 1.在散列(hashing)中,一個關鍵字的信息內容被用來確定唯一的一個值,稱位散列碼(hashcode)

 2.1. Rule: If the equals() method returns true, then hashCode() for both the objects must return the same value. Note that the reverse is not required. So, it is ok if the equals() method returns false but the hashCode() returns same value for both the objects.

2.2. The hasCode() method does not satisfy the requirement:
If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
For example, equals() will return true for: new Info("aa", "b", "c") and new Info("a", "ab", "c") but their hashCode() values will be different.

2.3 So we must overiding equals() and hascode() in bean ,assure the two object is equals

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章