dl at cs.oswego.edu
Sat Dec 19 16:02:21 UTC 2015
Here's an alternative that evades (or allows to be postponed) John's
slippery-slope concerns about overloading "==":
Anyfy equals, and adjust default implementation of boolean T.equals(any x)
for type (ref or val) T to the intrinsified, otherwise inexpressible:
if (bitwiseEqual(x, this)) return true; // pointer equality if ref
if (!(x instanceof T)) return false;
if (method T.equals(T) is not defined) return false;
return equals((T)x); // call specialized override
(Various optimizations may be possible.)
Any class or val type could still override this, and/or
introduce its T.equals(T) specialized override.
It might be challenging for people to write correct,
symmetric equals methods that span refs and vals, but not
impossible (which is OK since it should be rare).
I still think that doing something like this removes the need
to specially deal with Collection.contains and related methods.
More information about the valhalla-spec-experts