Groovy Closures

A Groovy closure, in simple terms, is an executable block of code that can be assigned to a variable, passed to a method, and executed.[9] Many of the enhancements Groovy has made to the standard Java libraries involved adding methods that take a closure as a parameter.

A closure is declared by placing code between curly braces. It can be declared as it is being passed to a method call, or it can be assigned to a variable and used later. A closure can take parameters by listing them after the opening curly brace and separating them from the code with a dash-rocket (->), like so:

 
def​ c = {a, b -> a + b}

If no parameters are declared in a closure, then one is implicitly provided: it’s called it. Take a look at the following ...

Get Grails 2: A Quick-Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.