Bind a java class as a closure into a groovy-script
- by chrsk
Is it possible to bind a closure written in java into a groovy-script. Is there an interface or something to implement so i can provide a closure?
Something like this?
public class Example implements Closure {
public void closure(Object... args) {
System.out.println(args[0]);
}
}
Bind this into the groovyscript.
Binding binding = new Binding();
binding.put("example", new Example());
groovyScriptEngine.run("foo.groovy", binding)
and use it in the foo.groovy like this:
example("Hello World")