Some scripting engines can compile scripting code into an intermediate form for efficient execution. Those engines implement the
Compilable interface. The following example shows how to compile and evaluate code contained in a script file:
Reader reader = new FileReader("myscript.js"); CompiledScript script = null; if (engine implements Compilable) CompiledScript script = ((Compilable) engine).compile(reader);
Once the script is compiled, you can execute it. The following code executes the compiled script if compilation was successful, or the original script if the engine didn’t support compilation.
if (script != null) script.eval(); else engine.eval(reader);
Of course, it only ...