On Thu, 25 Aug 2022 12:33:51 GMT, Nir Lisker <nlis...@openjdk.org> wrote:

>> `Node` adds InvalidationListeners to its parent's `disabled` and 
>> `treeVisible` properties and calls its own `updateDisabled()` and 
>> `updateTreeVisible(boolean)` methods when the property values change.
>> 
>> These listeners are not required, since `Node` can easily call the 
>> `updateDisabled()` and `updateTreeVisible(boolean)` methods on its children, 
>> saving the memory cost of maintaining listeners and bindings.
>
> modules/javafx.graphics/src/main/java/javafx/scene/Node.java line 1919:
> 
>> 1917:                             }
>> 1918:                         }
>> 1919:                     }
> 
> Because we can use Java 17 now, you can use pattern matching for 
> `instanceof`. Also, from what I see, `getChildren()` can never return `null`. 
> So, we can write
> 
> if (Node.this instanceof Parent parent) {
>     parent.getChildren().forEach(child -> child.updateDisabled());
> }

Since `getChildren()` is not final, one can easily override it and return null. 
Therefore, this check should still be done here. 
Maybe we even need to check that every child is not null, since again I can 
override `getChildren()` and return a list that allows null. (The default 
implementation in `Parent` throws an exception when adding a null child)

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

PR: https://git.openjdk.org/jfx/pull/841

Reply via email to