I have this short code here
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String foo = "print(2);";
Object s =engine.eval(foo);
System.out.println(s); // printing null
What i am trying to achieve is that i want the result that engine.eval(foo) will print to save it in a string variable example s value should be 2 , how can i realize it in this case that engine.val(foo) is not returning anything.