Java ScriptEngineManager无法正确处理大括号

时间:2018-02-12 02:01:53

标签: java scriptengine

示例代码:

ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
System.out.println(engine.eval("{1}/5"));

给出错误:预期操作数但找到/

1 个答案:

答案 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中按整数划分对象,说明问题发生的原因