In Effective Java Item 9 (Always override hashCode
when you override equals
) where it says
Many classes in the Java platform libraries, such as String, Integer, and Date, include in their specifications the exact value returned by their hashCode method as a function of the instance value. This is generally not a good idea, as it severely limits your ability to improve the hash function in future releases.
What does it mean ?
It means that you can't rewrite the hash function in later versions of your code to have better hashing properties. For example, the String.hashCode()
function is fast...but not very good. But it can't be changed anymore, because the hash code was specified and people have depended on that implementation in their own code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With