我这里有这个简短的代码
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String foo = "print(2);";
Object s =engine.eval(foo);
System.out.println(s); // printing null
我想要实现的是,我想要 engine.eval(foo) 将打印的结果将其保存在字符串变量中 example s value should be 2 ,在这种情况下我如何实现 engine.val(foo)没有返回任何东西。
汪汪一只猫
相关分类