Implementation of == and Object::equals
John Bossons
jbossons at gmail.com
Mon Apr 8 02:30:44 UTC 2024
I'm not sure that this is the right place to raise this, but don't know
where else to do so.
For identity types, == is simply a test of reference equality and so is a
useful first test in an overriding type-specific equals method.
For value types, the relationship is more subtle, since == is a test of
value equality, not reference equality. I suggest it be implemented as an
operator causing Object::equals to be invoked, so that if Object::equals is
overloaded (e.g. to first test equality of hash codes or otherwise modify
the default equals test), the overloaded method is automatically invoked
when == is used.
This would mean that Object::equals implements the == operator, rather than
the reverse, so that a specification that a == b always means a.equals(b),
whether implemented by the default test or by an overriding type-specific
method (that e.g. tests for equality of identity object field values). I
believe this would make value types (especially value trees) easier to use.
John
--
Phone: (416) 450-3584 (cell)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20240407/04837a91/attachment.htm>
More information about the valhalla-dev
mailing list