// Simple list with names. def names = ['groovy', 'grails', 'mrhaki'] // Simple closure. names.each { println 'Normal closure says: Hello ' + it + '!' } // 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
This code comes from mr haki's blog. What I like here is the ability to switch from Java to Groovy ! You can have the power of Java with the simplicity of Groovy
(and that's also a test post for the syntax highlighting plugin)
No comments:
Post a Comment
Share your feelings about this post, or this blog