Using Object Extensions

In this section, we’ll explore some additions to the mother of all classes, the java.lang.Object class. In Chapter 6, Working with Collections, we saw Groovy-added methods on Collections: each, collect, find, findAll, any, and every. These are not only available on Collections; we can also use these methods on any object. This gives us a consistent API to work with individual objects and collections alike—one of the benefits elicited in the Composite pattern (see Design Patterns: Elements of Reusable Object-Oriented Software [GHJV95]). Groovy has added non-collections-related convenience methods to Object, as well. We won’t go over all of those in this section—we don’t want this chapter to turn into a complete reference ...

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