Implementation of == and Object::equals
Roger Riggs
roger.riggs at oracle.com
Mon Apr 8 14:25:25 UTC 2024
Hi John,
This is covered under discussions of ==, specified in the VM spec as
implemented by the "acmp" bytecode
and described as "same"ness or "substitutability" on the
valhalla-spec-experts archive.
The discussion of substitutability for float and double along with more
general principles were discussed in February 2024.
See the archives for details:
https://mail.openjdk.org/pipermail/valhalla-spec-experts/2024-February/subject.html
Regards, Roger
On 4/7/24 10:30 PM, John Bossons wrote:
> 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/20240408/2db83cc7/attachment.htm>
More information about the valhalla-dev
mailing list