Proposal: Comparables.isCommutativelyComparable

Martin Buchholz martinrb at google.com
Sun Jun 9 01:20:54 UTC 2013


On Sat, Jun 8, 2013 at 8:50 AM, Doug Lea <dl at cs.oswego.edu> wrote:

>
> But there's nothing about interface Comparable that forces
> this to be true. It would be weird but legal if both
> are of form, say, "class C implements Comparable<Byte>".
>

The antisymmetric property prevents this from being legal.

"""The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for
all x and y. (This implies that x.compareTo(y) must throw an exception iff
y.compareTo(x) throws an exception.)"""


> Which means that you cannot compare them to each other.
>



More information about the core-libs-dev mailing list