Addition to Comparable interface

Mark Thornton mthornton at optrak.co.uk
Tue Mar 31 08:13:14 PDT 2009


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




More information about the coin-dev mailing list