Chapter 16Applying Compile-Time Metaprogramming

Unlike some dynamically typed languages with only runtime capabilities, Groovy offers both runtime and compile-time metaprogramming.

With runtime metaprogramming, explored in the previous chapters, we can postpone to runtime the decisions to intercept, inject, and even synthesize methods of classes and instances. For the most part, that’s all we need for metaprogramming. Compile-time metaprogramming is an advanced feature that’s useful in some special situations and is mostly used by framework/tool writers.

With Groovy we can analyze and modify a program’s structure at compile time. This can help make applications highly extensible, allowing us to add new cross-cutting features. For example, ...

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.