给定以下代码:
代码1:
FXMLLoader loader = new FXMLLoader();
Parent root = (Parent) loader.load(getClass().getResource("Screen1.fxml"));
Screen1Controller controller = loader.getController();
if(controller == null)
System.out.println(" controller is null");
else System.out.println("controller is not null");
输出:
控制器为空
代码2:
FXMLLoader loader = new FXMLLoader(getClass().getResource("Screen1.fxml"));
Parent root = (Parent)loader.load();
// FXMLLoader loader = new FXMLLoader();
// Parent root = (Parent) loader.load(getClass().getResource("Screen1.fxml"));
Screen1Controller controller = loader.getController();
if(controller == null)
System.out.println(" controller is null");
else System.out.println("controller is not null");
输出:
控制器不为空
我以为他们会给出相同的结果?不是吗?