Metaprogramming
A complete discussion of Groovy’s metaprogramming features would be beyond the scope of this primer, but it will be helpful to have some understanding of them as you begin to work with Grails. Groovy’s metaprogramming can make us much more productive as developers. With it, Grails adds methods to our objects that we are going to need and use but never write.
So here’s Groovy metaprogramming in a nutshell: Groovy provides mechanisms for adding methods and properties to classes at runtime, and/or without touching their code. This is done in several ways; we’ll discuss two that are used in Grails.
Every Groovy class has a metaClass, which can be written by someone else and assigned at runtime. Any methods or properties added in ...
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