-
public class TestA {
-
public static void main(String[] args) throws Exception {
-
String str = "(a >= 0 && b <= 5)";
-
ScriptEngineManager manager = new ScriptEngineManager();
-
ScriptEngine engine = manager.getEngineByName("js");
-
engine.put("a", 4);
-
engine.put("b", 5);
-
Object result = engine.eval(str);
-
System.out.println("结果类型:" + result.getClass().getName() + ",计算结果:" + result);
-
}
-
}
输出结果:
结果类型:java.lang.Boolean,计算结果:false
阅读(3719) | 评论(0) | 转发(0) |