示例代码:
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
System.out.println(engine.eval("{1}/5"));
给出错误:预期操作数但找到/
答案 0 :(得分:0)
以下代码正常运行!
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
try {
System.out.println(engine.eval("1/5"));
} catch (ScriptException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
您不能在Javascript
中按整数划分对象,说明问题发生的原因