For a fxml controller class that would map to an fxml control, such as:
public MyController
{
@FXML
private Button button;
}
Is it possible to declare the button
field as final? If it was done, the java compiler (javac) would flag an error about that field not being initialized.
It is understood that the button field will be eventually initialized using the @FXML injection. Albeit, javac does not fully understand this, or even how it would be done.
Although the final qualifier may not be needed, however, it would be good to enforce to minimise potential mutability related errors, particularly when it is never intended to change.
Although I do not understand the complexity on how the fxml workings initialize its component, except that it uses reflection. Having said that, and generally for fields that rely on injection and reflection, then the final qualifier cannot exist on such field?
A final field must be define at least in the constructor of the class. When using @FXML injection the fields will be injected / defined after that constructor has been called by using reflection. Therefore you can't define them as final.