We have the operators `<`, `<=` `>=` and `>` which...
# language-evolution
k
We have the operators
<
,
<=
>=
and
>
which all call
compareTo
but they all check for inequalities. Would there be any interest in a special operator,
<==>
, with the semantics that
a <==> b
is equivalent to
a.compareTo(b) == 0
? Let's call it the "extended spaceship operator" since the normal spaceship operator
<=>
is already well-known in other languages and has different semantics (it returns an integer). The use case is when comparing
BigDecimals
for value equality (where
a == b
is not what is wanted because it includes scale).
s
It would also be relevant for some floating point edge cases. But even then, I suspect the use cases are few enough that a dedicated operator would be very rarely used, and I think a rarely-used operator is likely to be less clear than just writing out compareTo in full.
6