我想使用其内置的Javascript引擎修改Java程序中的变量。这样可以吗?
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
Integer x = new Integer(11);
Integer y = new Integer(20);
Bindings bindings = new SimpleBindings();
bindings.put("x", x);
bindings.put("y", y);
engine.eval("if (x > 10) {" +
" print(\"Entered condition\");" +
" y = 90;" +
"}", bindings);
System.out.println(bindings.get("y"));
以上打印20。