JavaFX runtime main method

后端 未结 2 1924
天命终不由人
天命终不由人 2020-12-21 05:42

The Hello World-Tutorial of JavaFX says:

The main() method is not required for JavaFX applications when the JAR file for the application is created wi

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-21 06:18

    One possible answer would probably be, that there is a main method declared in Application. And if another class, which extends from Application, has its own main method, the code would still be valid and the main method of Application will be ignored::

    class Main extends OtherMain {
        public Main(String text) {
            System.out.println(text);
        }
    
        /* If this method is removed, the main-method is called from OtherMain */
        public static void main(String[] args) {
            new Main("Called from Main-Class");
        }
    }
    
    class OtherMain {
        public static void main(String[] args) {
            new Main("Called from Other-Main-Class");
        }
    }
    

    Does this make sense?

提交回复
热议问题