I'm trying to define a generic Formula, e.g. "a+b" and use it to pass parameters. Any ideas how to make this thing work?
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
String Formula="a+b";
engine.put("Formula", Formula);
engine.put("a", "3");
engine.put("b", "4");
res = engine.eval("r = Formula").toString();
System.out.println(res);
The output of the above code is "a+b" and not 7 as expected.