Groovy Metaprogramming

Groovy metaprogramming tutorials. Runtime and compile-time techniques including MetaClass, ExpandoMetaClass, categories, mixins, and AST transforms.

Groovy Advanced AST Transforms – Part 2 with 10+ Examples

Groovy advanced AST transforms beyond @ToString and @Canonical. Part 2 covers @TupleConstructor, @MapConstructor, @Delegate, @Memoized, @AutoClone, @Sortable, @Newify, and combining multiple transforms. “The best boilerplate is the boilerplate you never write. AST transformations are your compiler doing your chores.” Dierk König, Groovy in Action Last Updated: March 2026 | Tested on: Groovy 5.x, Java 17+ | Difficulty: Intermediate | Reading Time: 20 minutes This is Part 2 of our AST transformations series. Part 1 covered the essentials – @ToString, @EqualsAndHashCode, ... Read More

Groovy Custom Annotations – Create Your Own with 10 Tested Examples

Groovy custom annotations are versatile. See 10 tested examples covering annotation declaration, retention policies, AST transformations, and runtime processing. “Annotations are metadata that give your code a voice – they tell the compiler, the runtime, and other developers what your intentions are without cluttering your logic.” Joshua Bloch, Effective Java Last Updated: March 2026 | Tested on: Groovy 4.x / 5.x, Java 11+ | Difficulty: Advanced | Reading Time: 18 minutes Groovy ships with a rich set of built-in annotations ... Read More

Groovy @Builder Annotation – Builder Pattern Made Easy with 10+ Examples

Groovy builder pattern with the @Builder annotation with 10+ examples. DefaultStrategy, SimpleStrategy, ExternalStrategy, InitializerStrategy explained. “The builder pattern separates the construction of a complex object from its representation. Groovy’s @Builder does this without writing a single builder class.” Gang of Four, Design Patterns Last Updated: March 2026 | Tested on: Groovy 5.x, Java 17+ | Difficulty: Intermediate | Reading Time: 19 minutes When a class has many fields – some required, some optional – constructors become unwieldy and map-based construction ... Read More