Closure

Closure has usually been associated with functional languages. Groovy provides a very easy way of creating closure objects. A Groovy Closure is like a code block written in curly braces. Many people associate Closure to be an anonymous function in Java.

Closure in Groovy may accept arguments and returns a value. By default, the last statement in a Groovy Closure is the return statement. It means that if you are not explicitly returning any value from Closure, it will by default, returns the output of the last statement of Closure. Commonly, we define a Closure like this {argument list-> closure body}. Here, an argument list is a comma separated value that Closure accepts. Arguments are optional. If no argument is specified, then one implicit ...

Get Mastering Gradle 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.