From: "Rodney Waldhoff" <[EMAIL PROTECTED]> 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). Crazy! > I suggest that we replace the block above with simply: > > return ((Comparable)o1).compareTo(o2); +1 > 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 change. > (The addition of collections.primitives probably justifies a new major > version number anyway.) Agreed. If we do go to 3.0, then could we delete the deprecated iterators and comparators in the main package? Stephen -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
