commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <>
Subject Re: [collections] ComparableComparator executes all comparisons twice!?
Date Wed, 08 Jan 2003 23:45:33 GMT
From: "Rodney Waldhoff" <>
Subject: [collections] ComparableComparator executes all comparisons twice!?

> I recently noticed something that I found rather surprising.  Given two
> Comparables compA and compB, ComparableComparator always executes both
> compA.compareTo(compB) *and* compB.compareTo(compA)  (and throws
> ClassCastException if the two results are inconsistent).

> I suggest that we replace the block above with simply:
>   return ((Comparable)o1).compareTo(o2);

>  Unfortunately ComparableComparator does in fact state in its
> JavaDocs that it "throws ClassCastException if the compareTo of both
> objects do not provide an inverse result of each other as per the
> Comparable javadoc.", which does make this a small change in the
> ComparableComparator contract.  This change in contract would of course
> imply a new major version number, per the commons versioning guidelines.
I suppose so, although personally I wouldn't be hung up on this particular

> (The addition of collections.primitives probably justifies a new major
> version number anyway.)

If we do go to 3.0, then could we delete the deprecated iterators and
comparators in the main package?


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message