APPENDIX H MORE ON CLOSURES

Chapter 9 introduced closures and demonstrated their importance when iterating over collections. We also described general aspects of closures including closure parameters. Here, we consider other details concerning closures including default parameters, the distinction between closures and methods, and closures and scope rules. We also tabulate and describe the methods for Lists, Maps, and Ranges that take a closure as parameter.

H.1 CLOSURES AND AMBIGUITY

Example 06 in Chapter 9 outlined how a closure appearing as the final actual parameter to a method call may be removed from the list of actual parameters and placed immediately following the closing parenthesis. If meth represents a method with three parameters: ...

Get Groovy Programming 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.