Addition to Comparable interface
mthornton at optrak.co.uk
Tue Mar 31 05:31:44 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:
It is valid for reduced ranges of integers, notably when the values are
known to be positive.
More information about the coin-dev