Last paragraph Paragraph 9 of Effective Java, 2nd Edn, J. Bloch says that for value classes such as Integer , String , Date , etc. returning the exact value function of this class as hashCode is not a good idea.
So, the Integer class that returns the value an integer, which it represents as the hashCode its instance, is not so good.
There is also no hashCode() String that returns an integer value that is directly displayed from the shared content, i.e. the characters that the String instance has.
These hashCode() -s are clearly contractual.
It seems to me that this is a good idea, not a bad one. hashCode -s change as values change across objects, and these hashCodes “normalized” before they are distributed into buckets a HashMap / HashSet so that hashCode -s records do not form an offset over which the bucket will enter the record.
What I am missing here is what makes matching the class value directly with hashCode "bad idea"?
TIA
// =============================
EDIT
pls also see comments in response to Steve Sieber in connection with this.
source share