Proposal: Comparables.isCommutativelyComparable

Doug Lea dl at
Sun Jun 9 14:09:54 UTC 2013

On 06/08/13 21:52, Martin Buchholz wrote:
> On Sat, Jun 8, 2013 at 8:50 AM, Doug Lea <dl at
> <mailto: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);
> 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.

Right, including the case where the class itself was declared with
raw types. I should have stated that the method spec should say
that a true return means YES, a false return means "not validated
under best effort".


More information about the core-libs-dev mailing list