7.3 Custom Methods Using the Extension Modules
Groovy 2.x helps us move quickly beyond the privilege of using methods added to the GDK. Using the extension-modules feature, we can add our own instance or static methods to existing classes at compile time and use them throughout the application at runtime. Let’s take a look at the simple steps we have to follow for this using an example.
We need two things for this feature to work: First, a method we want to add must be defined in an extension-module class. Second, we need a descriptor file in the manifest file to tell the Groovy compiler what extension-module classes to look for.
Let’s create two extension methods—an instance method and a static method—both on the String class, to get the ...
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