On Mon, 25 Nov 2024 12:45:43 GMT, Marius Hanl <mh...@openjdk.org> wrote:

>> `HashSet` uses `Object.equals`, which can be overridden by user code, and 
>> this would break the logic. It's the _instance_ that wants to be notified.
>
> Good point, I never ever did that for `Node`s (and I don't know why I would 
> need to), but you are right, it is indeed possible and therefore a possible 
> scenario.

I think this is overly cautious.  Overriding equals on a class that did not 
implement equals in a hierarchy you don't control  is not a very reasonable 
scenario.  You will not be able to call `super.equals` with reasonable results 
if the hierarchy did not implement it in the first place.  This is because 
there may be private data that you can't access for your equality comparison 
(and `Node` has lots of that).  We also use `WeakHashMap`s in several areas 
already with subtypes of `Node`s as keys (I found `Region`, `Parent` and 
`TreeView` being used as keys), so this kind of override should probably be 
documented as being unsupported on `Node`.

Perhaps it should even be made final so FX internals can rely on it being 
correct.

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1607#discussion_r1856882523

Reply via email to