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 ]