Addition to Comparable interface

Mark Thornton mthornton at
Tue Mar 31 04:29:00 PDT 2009

Roy van Rijn wrote:
> AUTHOR(S): Roy van Rijn
> Currently the interface Comparable only has one method:
> int compareTo(Object o);
> This is perfect and enough to work with. But the 'int' you have to
> return is a bit messy and unclear.
> 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;
> Its much more clear what you need to return when you are implementing
> the Comparable interface. The addition won't affect any previously
> written code and won't break backwards compatibility..
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.

Mark Thornton

More information about the coin-dev mailing list