您需要获取
scriptEngine实例而不是
scriptEngineFactory
final scriptEngine engine = engineFactory.getscriptEngine();if (engine instanceof Compilable) {...
为何全部
Compilable?因为这些脚本引擎将来可能会被编译。但目前尚不支持,因此它们都实现了此接口。您可以尝试编译空字符串:
if (engine instanceof Compilable) { try { ((Compilable) engine).compile(""); } catch (Error e) { System.out.println(engineName + " script compilation is not supported."); } catch (scriptException e) { e.printStackTrace(); } System.out.println(engineName + " script compilation is supported."); } else { System.out.println(engineName + " script compilation is not supported."); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)