Does the specific signed integer matter when implementing compareTo in a Comparable <Type> class?
- by javanix
When implementing compareTo(), does the degree of "difference" need to be taken into account?
For instance, if I have 3 objects, C1, C2, and C3, such that C1 < C2 < C3.
Should C1.compareTo(C2) return an integer that is less than C2.compareTo(C3)?
The documentation for the Comparable interface doesn't seem to specify one way or another, so I'm guessing the degree doesn't matter, but it would be nice to know if there is some advantage returning a specific number (for example, improving TreeSet sort speed or something).
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Comparable.html#compareTo(T)