JDK-8181769: Introduce interface with type-safe equals

Dmytro Sheyko dmytro.sheyko at gmail.com
Mon Jun 19 11:22:07 UTC 2017


Recently noticed that RFE JDK-8181769 (Introduce interface with
type-safe equals) is closed as duplicate of some other RFE. However I
think these RFEs are unrelated.
The idea behind JDK-8181769 is NOT to supply custom equality functions
to collections, but to provide means to enforce compile-time type

Long a = ...
String b = ...

`a.equals(b)` is OK for javac, but this is most likely logical error
because it always evaluates to false;
`a.compareTo(b) == 0` causes compilation error and hence prevents logical error;
`a.isEqualTo(b)` is actually the proposal. it should cause compilation
error as 'compareTo' does, but in contract to `compareTo` 1) it could
be more efficient than `compareTo` because here we do not care Which
object is greater or less than the other one; 2) `isEqualTo` could
also be used for classes that does not have any sense to implement
`Comparable<T>` interface, e.g. `java.util.List`, `java.util.Set`,
`java.util.Map`, complex numbers etc.

Therefore I would ask to reopen this RFE.


More information about the core-libs-dev mailing list