Within any one execution of the Java application, the hash code contract requires that each invocation of the hashCode method on the same instance of class C must consistently return the same result as long as the fields used for the equals comparison remain unchanged
Yes it is wrong, but not in the way that you think.
The contract does not demand what has been stated, but something else, specifically, that "If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result." This is different to what has been stated.
The challenge now is to "change the fields" used for the equals comparison, while still meeting the real contract. i.e. to contradict the misinterpretation and the reality. It can be done
<spam>
JTiger
unit test framework will allow you to assert that your objects meet all aspects of the equals/hashCode method contracts among many other useful assertion features.
http://www.jtiger.org/ I plan to release it within the next two weeks - political issues pending.
</spam>
[ March 01, 2005: Message edited by: Tony Morris ]