Addition to Comparable interface (original) (raw)
Roy van Rijn roy.van.rijn at gmail.com
Tue Mar 31 08:46:08 PDT 2009
- Previous message: Addition to Comparable interface
- Next message: Proposal idea - generators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Ah yes, much better, thanks!
On Tue, Mar 31, 2009 at 5:40 PM, Joseph D. Darcy <Joe.Darcy at sun.com> wrote:
Mark Thornton wrote:
Roy van Rijn wrote:
FEATURE SUMMARY: The return value of the Comparable interfae could be made a lot clearer if it would have the following static variables: public static int BEFORE = -1; public static int EQUAL = 0; public static int AFTER = 1;
This might give the impression that the only values returned by compareTo are -1, 0, 1 which is certainly not true. The interface only requires that the sign of the returned value reflect the ordering.
That might be a problem indeed, but the javadoc should still indicate its possible to use any positive and negative integer value. The problem I've seen a lot is the following, even in large corporate programs, when people compare integers like this: As Reinier points out this is the wrong list for this proposal. However a better solution might be to add Integer.compare(int,int) and Long.compare(int, int) methods, and encourage people to use tham inside of writing the comparison themselves. Mark Thornton Yes; as noted the request is off-topic for Project Coin since it is a pure libraries change. I agree a set of two-argument int and long (and float and double ...) compare methods on primitive types would be a fine addition to the platform libraries in JDK 7: 6582946 Add suite of compare(T, T) methods for ints, longs etc http://bugs.sun.com/viewbug.do?bugid=6582946 -Joe
- Previous message: Addition to Comparable interface
- Next message: Proposal idea - generators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]