I have the following code which works:
ScriptEngine jsEngine = ScriptEngineManager.new().getEngineByName("nashorn");
jsEngine.eval("some script");
jsEngine.invokeMethod(jsEngine.eval("foo"), "bar");
but I want to do use a pre-compiled script so I don't have to evaluate the script every time I need to run it, so I'm trying;
ScriptEngine jsEngine = ScriptEngineManager.new().getEngineByName("nashorn");
CompiledScript compiledJS = jsEngine.compile("some script");
but then I'm not sure what to do with CompiledScript, how do I invoke a method? it doesn't implement anything else than eval() apparently: https://docs.oracle.com/javase/8/docs/api/javax/script/CompiledScript.html
You call the method?
Here are few examples: http://www.programcreek.com/java-api-examples/index.php?api=javax.script.CompiledScript
Example: