O'Reilly logo

Groovy Programming by John Savage, Kenneth Barclay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 9 CLOSURES

Groovy closures are a powerful way of representing blocks of executable code. Since closures are objects, they can be passed around as method parameters, for example. Because closures are code blocks, they can also be executed when required. Like methods, closures can be defined in terms of one or more parameters. A significant characteristic of closures is that they can access state information. This means that any variables in scope when the closure is defined can be used and modified by the closure.

One of the most common uses for a closure is processing a collection. For example, we can iterate across the elements of a collection and apply the closure to them. Groovy’s closures are one feature that make developing scripts ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required