Always override
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 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.