Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is an overwritten function ignored by super Java FX Application (extend)?

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):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading