Script
interface, and run a Groovy Script as a class which implements this interface from Java.
public interface Script { public int execute(); }
public class GroovyScriptWrapperImpl extends GroovyScriptWrapper<Script> { }With this definition, we have defined that our wrapper wrap scripts which implement the
Script
interface.ScriptWrapper<Script> wrapper = new GroovyScriptWrapperImpl(); Script script = wrapper.getScript();Note that we also could do all of this with the more simple code:
ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>(){ };
public int execute() { return 10; }We can now install the Script:
File file = new File(<our script file>); Script script = wrapper.installScript(file);And now we can run the method:
int value = script.execute(); // value is 10
Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence