我使用 java ScriptEngine 来执行一个可以改变共享 Java 类的脚本。我想知道,是否可以在 java 类中支持动态创建的变量?
// create a script engine manager
ScriptEngineManager factory = new ScriptEngineManager();
// create a JavaScript engine
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.put("javaclass", jClass);
engine.eval("javaclass.propertyThatDoesNotExist = 'test'"); // throws exception