I am trying to learn JavaFX, and struggling a bit with boilerplate code that works but I’m not clear why.
I have a line like this which is boilerplate provided by IntelliJ:
Parent root = FXMLLoader.load(getClass().getResource("View.fxml"));
And I am looking at an example elsewhere which has a line that appears to perform a similar function:
FXMLLoader loader = new FXMLLoader(getClass().getResource(“View.fxml”));
Then the first program goes on to use root to set up a scene on the stage and the second one goes on to use loader in the same way.
In one case we seem to define an object of type Parent, create an object of type FXMLLoader, and put that into Parent. In the other case we seem to just create an object of type FXMLLoader and use it directly.
It looks to me as though the Parent object extends Node, which extends Object itself. Meanwhile, FXMLLoader extends Object directly. There seems to be no reason to expect an FXMLLoader object would meet the requirements to be a Parent object, but we are assigning it as though it does.
So, how can FXMLLoader be a Parent? What am I missing here?