CHAPTER 5Closures

You have already seen some examples of closures in previous chapters. The concept of closures is new to most Java developers, and closures might seem a bit foreign when you see them for the first time. By working your way through the examples in this chapter, you will get a much better understanding of closures, how they work, and how to use them efficiently. Closures are important in Groovy; almost any real-life example in Groovy will use closures, and a good understanding of them is essential if you want to get the most out of the language.

5-1. What Is a Closure?

A closure is simply an anonymous block of code. The most important thing you need to know about closures is that they are objects of type groovy.lang.Closure: you ...

Get Groovy and Grails Recipes now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.