Equality

Doug Lea dl at cs.oswego.edu
Mon Dec 21 16:50:56 UTC 2015


On 12/19/2015 05:20 PM, Brian Goetz wrote:

>> Right. I agree that the signature must compatibly change,
>> but not necessarily that anything else does.
>
> OK, we're on the same page.

Where I think this page says that interfaces with existing methods
accepting Object args can in principle be anyfied without strictly
requiring (but usually strongly encouraging) implementation class rework.
There is a way to enable/translate analogs of Object methods,
in particular equals().

We wouldn't normally recommend blanket anyfication of interfaces,
but Collections is the main one that everyone hopes will be somehow
doable.

The full story on this has a few more quirks though.
It gets uncomfortable to cope with synchronized(obj),
Object.wait, and Object.notify: Semantically, synchronized(val)
and notify would be no-ops, and wait would block forever.
Which would be OK, because no sensible general-purpose implementation
of say, collection.contains would use any of these.

And, as John almost noted, compareTo/Comparable needs
treatment similar to my hybrid version of equals.

-Doug



More information about the valhalla-spec-experts mailing list