如果你只需要访问某个
Class
实例,简单使用
ClassName.class
:
// also changed this to use the loop variable instead of loading the same scene twice
Parent root = FXMLLoader.load(ViewManager.class.getResource(sceneName.toString()));
sceneContainer.put(sceneName, new Scene(root, Bounds.HEIGHT, Bounds.WIDTH));
一般使用
static
不过,应该避免太频繁。单件可能是更好的选择。如果你能通过
ViewManager
所有需要它的类的实例…(看看依赖注入可能是个好主意。)