Today, I used Java 6 Scripting API to evaluate logical expressions. Here is an example:
}
}
//result will be trueimport javax.script.*; public class EvalScript { public static void main(String[] args) throws Exception { // create a script engine manager ScriptEngineManager factory = new ScriptEngineManager(); // create a JavaScript engine ScriptEngine engine = factory.getEngineByName("JavaScript"); // evaluate JavaScript code from String Boolean result=(Boolean)engine.eval("'sometext'=='sometext'");
}
}
No comments:
Post a Comment