Lets say, we have the following class:
import javafx.application.Application;
import javafx.stage.Stage;
public class Test extends Application
{
public Test()
{
System.out.println("Constructor");
}
@Override
public void start(Stage primaryStage) throws Exception
{
System.out.println("start");
}
public static void main(String... args)
{
System.out.println("main");
}
}
It's derived from Application
but it doesn't use any of its methods. Usually you start a JavaFX application by calling launch(args)
in the main.
When I start this program the only output is "main", so the constructor and start aren't called, but the program doesn't terminate because there is a JavaFX Application thread running. But where does it come from?
I did some debugging and found out that the thread is started from the main thread before the main method runs. The stack trace starts with NativeMethodAccessorImpl
.
To get even weirder: when I start the main method from a different class, the JavaFX Application thread isn't started:
public class Test2
{
public static void main(String[] args)
{
Test.main(args);
}
}
So what kind of black magic is this?