Skip to content

Instantly share code, notes, and snippets.

@vmi
Last active August 30, 2021 09:27
Show Gist options
  • Save vmi/18395fae0e01d338c04d332e51f50026 to your computer and use it in GitHub Desktop.
Save vmi/18395fae0e01d338c04d332e51f50026 to your computer and use it in GitHub Desktop.
Script Engine Test
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class Main {
public static void main(String[] args) throws ScriptException {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
System.out.println(engine.toString());
Object result = engine.eval("1 + 2");
System.out.println("Result: " + result);
}
}
@vmi
Copy link
Author

vmi commented Aug 30, 2021

Java11

Warning: Nashorn engine is planned to be removed from a future JDK release
jdk.nashorn.api.scripting.NashornScriptEngine@3ec300f1
Result: 3

GraalJS 21.2.0

com.oracle.truffle.js.scriptengine.GraalJSScriptEngine@335eadca
Result: 3

Java17(Preview)

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Object.toString()" because "engine" is null
	at Main.main(Main.java:10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment