通过反射创建Node

  1. 获取类Class<?> classType = Class.forName("javafx.scene.control.Button")

  2. 获取构造方法Constructor<? extends Node> constructors = node.getClass().getConstructor(String.class)

  3. 创建实例对象Node node2 = constructors.newInstance("I'm a Text")

  4. 获取指定方法Method method = node.getClass().getMethod("setText", String.class)

  5. 调用方法method.invoke(node, "No, I'm a button")