CSDN博客

img Reve

Always override Object.equals() and Object.hashCode() in the same time

发表于2004/7/12 9:52:00  1213人阅读

分类: Java

Always override Object.equals() and Object.hashCode() in the same time. I had met with such bugs serveral times and it was a hard time for me to figure out such bug.

Quotes:
http://www-106.ibm.com/developerworks/library/j-jtp06294.html
Hashing it out
In "Hashing it out," I outlined the basic rules for correctly overriding Object.equals() and Object.hashCode(), in particular that equal objects (according to equals()) must have equal hashCode() values. While this rule is fairly easy to follow once you know it (and some IDEs have wizards for defining both for you in a consistent manner), if you override one of these methods and forget to override the other, this bug can be very difficult to detect through inspection -- because the error is not in the code that is present, but in the code that is absent.
0 0

相关博文

我的热门文章

img
取 消
img