直接可以穿一个字符串运行
private static void test(String pm1) {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
Object result;
try {
result = engine.eval(pm1);
System.out.println("a + b = " + result);
} catch (ScriptException e) {
e.printStackTrace();
}
}
改编于:http://blog.csdn.net/sdyy321/article/details/6959199
时间: 2024-11-10 12:03:10