peter
peter

Reputation: 8473

Java platform libraries Hashcode

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 ?

Upvotes: 5

Views: 189

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198461

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.

Upvotes: 4

Related Questions