I have a problem regarding Java FX and the implementation of the very weird Application. Let me show it with code:
Imagine a basic Application:
import javafx.application.Application;
import javafx.stage.Stage;
public class JavaFXApp extends Application {
// constructor, ...
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
// important stuff
initialize();
// important stuff
stage.show();
}
public void initialize() {
System.out.println("default");
// basically abstract
}
// and other functions.
}
and it’s extension (as is intended):
public class JavaFXAppExtended extends JavaFXApp {
// constructor, ...
@Override
public void initialize() {
System.out.println("extended");
}
}
Now the calling of JavaFXApp yields no problem to my eye. But when calling JavaFXAppExtended, the @Overwrite is basically ignored and the initialize from the parent class is called. Thereby:
JavaFXApp.main(args);
-> default
JavaFXAppExtended.main(args);
-> default
whereby "extended" was expected.
So, did I miss something important? Is this illegal? Am I not experienced enough? Might this just be a bug? I don’t know. But I want to know.
>Solution :
Actually JavaFXAppExtended.main(args) calls the static JavaFXApp.main as there is no main in JavaFXAppExtended. There remains no trace in the calling code to JavaFXAppExtended. Exactly the same code as JavaFXApp.main(args).
There is no inherited this in static functions. Hence `JavaFXApp.launch is called.