PROPOSAL: Equivalence operators (formerly titled

Vilya Harvey vilya.harvey at gmail.com
Sat May 9 04:14:50 PDT 2009


Hiya

2009/5/9 Mark Thornton <mthornton at optrak.co.uk>:
> Why can't we overload >= and <= instead in the same way as < and > (i.e.
> only apply to Comparable types which are NOT convertable to primitives).

This is exactly what I proposed a few months ago. I ended up
withdrawing the proposal because it gives you a strange-looking
asymmetry with == and !=. You can't == or != to be based on Comparable
because it would break way too much code, but without changing them,
you end up with statements like this being valid:

if (a < b)
    ...
else if (a > b)
    ...
else if (a == b)
    ...
else
    ...

There's also the possibility of the operators causing a
ClassCastException to watch out for, as well as a
NullPointerException.

I still like the idea myself, but it certainly has the potential to be
confusing.

Hope that helps,
Vil.



More information about the coin-dev mailing list