Proposal: Sameness operators
mthornton at optrak.co.uk
Thu Apr 2 05:48:15 PDT 2009
Tom Hawtin wrote:
> Reinier Zwitserloot wrote:
>> Why can't we use compareTo and equals?
> * compareTo may well be unreasonably inefficient.
> * equals handles nulls (asymmetrically), compareTo does not
> * equals does test-and-cast (event for generic types - urgh),
> compareTo uses generics
> * equals does not throw ClassCastException, compareTo does (but
> probably shouldn't with generics)
> Therefore, new methods please. I'm sure you are aware the whole subject
> of operator overloading in general is a minefield.
a.compareTo(b) == 0 and a.equals(b) are not always the same, sometimes
for very good reasons. I seem to remember that there is at least one
such class in the Java platform.
More information about the coin-dev