以下是引用freish在2009-11-18 14:37:16的发言:
jdk1.6可以很容易做到
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
也是有eval方法的!
谢谢,试了一下,这个方法可以运行!
import javax.script.*;
public class TestEval {
public static void main(String[] args) throws Exception{
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
String str = "4+3-5+6";
System.out.println(engine.eval(str));
}
}