How does FXMLLoader load the FXML's controller?

前端 未结 2 1801
长情又很酷
长情又很酷 2021-01-12 11:14

What happens when I call FXMLLoader#load() in JavaFX?

Suppose the FXML controller extends a class that has a constructor. Will there be assurance that the construct

2条回答
  •  无人共我
    2021-01-12 11:53

    I'm not entirely sure what you are trying to do but normally the controller should not extend a textfield.

    That aside, this is basic java stuff: textfield has an empty constructor, your controller has none so java will (by default) call the empty constructor available in TextField. The TextField constructor will by default (even if it's not in the code) call the constructor of the class it extends and so on. There is no way to construct an object in java without a constructor being called.

提交回复
热议问题