Groovy Closure

Method Reference

public class JavaObject {
 public static void javaSays(final String s) {
  System.out.println("Java says: Hello " + s + "!");
 }
}
 
// Groovy method to convert to closure.
def groovySays(s) {
 "Groovy says: Hello ${s}!"
}
// Use .& syntax to convert method to closure.
names.each(this.&groovySays)
 
// Convert Java method to closure and use it.
def javaSays = JavaObject.&javaSays
names.each javaSays