为什么JavaFX Application.launch()将class作为参数? [英] Why JavaFX Application.launch() takes class as an argument?
问题描述
我是javaFx的新手,对源代码有些了解,并对以下问题有所疑问 用于启动应用程序的Application.launch函数.
I'm new to javaFx and looked a bit into source code and have a question regarding Application.launch function that is used to start an app.
签名如下:
public static void launch(Class<? extends Application> appClass, String... args)
我的问题是为什么它看起来不是这样:
And my question is why it doesn't look like this:
public static void launch(Application app, String... args)
作者以课堂为论点试图达到什么目的?
What authors try to achieve by taking class as an argument?
推荐答案
因为Application
的实例化是一项复杂的任务,FX开发人员必须对此进行控制.
Because an instantiation of the Application
is a complex task which FX developers have to have the control over.
Application
实例:
- 需要"FX工具箱"进行预先初始化
- 针对桌面,jnlp和插件模式而有所不同
- 需要特定的时间
- 应在特殊的启动器"线程上调用
- 应触发应用程序生命周期事件
- 应从CLI或jnlp文件读取应用程序参数
因此,您仅提供要启动的类名,而JavaFX会完成所需的所有工作,包括为您创建一个对象.
Thus you provide only class name to launch and JavaFX do all the work required, including creating an object for you.
这篇关于为什么JavaFX Application.launch()将class作为参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!