How does one handle a java method which returns a non-public sub-type via reflection?

Kevin Rushforth kevin.rushforth at oracle.com
Fri Jan 26 18:14:48 UTC 2018



jeffrey kutcher wrote:
>  
>   VBox class hierarchy shows getChildren() is implemented in Parent
> and Pane. vbox.getChildren() returns an instance of Parent which is
> protected rather than public found in Pane. Accessing the List
> returned by Parent is an illegal reference because it is protected
> while accessing the List returned by Pane should be legal, but
> this isn't whats returned.
>
> VBox Class Hierarchy:
>
> java.lang.Object
> javafx.scene.Node
> javafx.scene.Parent -> protected ObservableList<Node> getChildren​()
> javafx.scene.layout.Region
> javafx.scene.layout.Pane -> public ObservableList<Node> getChildren()
> javafx.scene.layout.VBox
>
> Class instance of vbox.getChildren() is:
>
> vbox.getChildren().getClass() -> class javafx.scene.Parent$3
>
> Pane is widening the access restrictions of Parent. Is this intentional?
> Does it have any effect? Should Parent's access restrictions of getChildren()
> be public or should Pane's be protected?
>
> My thought is public for both.
>   

Yes, this is intentional. It is fine for a subclass to widen the access 
from protected to public. No, we don't want to make Parent::getChildren 
public, since there are some subclasses that do not want to expose 
direct access to application.

-- Kevin



More information about the jigsaw-dev mailing list