7.1 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access