Addition to Comparable interface
Joseph D. Darcy
Joe.Darcy at Sun.COM
Tue Mar 31 08:40:57 PDT 2009
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/view_bug.do?bug_id=6582946
-Joe
More information about the coin-dev
mailing list