This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Originally posted by Campbell Ritchie: [NITPICK] Not quite. You can, at least in theory, have two different objects return identical hash codes.[/NITPICK]
Indeed. Furthermore, the API for compareTo() specifies that compareTo() does not have to return equal simply because equals() does (and vice-versa).
It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."
- Adam [ July 31, 2006: Message edited by: Adam Nace ]
Joined: Jan 29, 2003
Good catch, guys. I once had written if equals() says true the others should agree. That much I think is actually true. Donno why I changed it. And I did say "should" rather than "MUST" on the other.