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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access