Proposal: Comparables.isCommutativelyComparable

Martin Buchholz martinrb at
Sun Jun 9 01:52:40 UTC 2013

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

> Suppose you have two objects, x and y, both of the same
> type (x.getClass() == y.getClass()) and both known
> to be instanceof Comparable.
> Can you compare them? That is, can you safely call
>   (Comparable)x).compareTo(y);
> I'm surprised that this hasn't come up for consideration
> before. Or maybe I haven't noticed previous discussions?

Probably others tried and gave up, because you cannot actually get a
reliable answer - you can only get YES NO DUNNO, because some of the
generic type information you need may have been erased. My favorite example

<T extends Comparable<T>> interface LexicographicList<T>
extends Comparable<List<T>>, List<T>

More information about the core-libs-dev mailing list