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.” Last Updated: July 2026 | Tested on: Groovy 5.0.6, Java 17+ | Difficulty: Intermediate | Reading Time: 20 minutes This is Part 2 of our AST transformations series. Part 1 covered the essentials – @ToString, @EqualsAndHashCode, @Canonical, @Immutable, and @Builder. Those ... 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.” Last Updated: July 2026 | Tested on: Groovy 5.0.6, Java 17 | Difficulty: Advanced | Reading Time: 18 minutes Groovy ships with a rich set of built-in annotations – @Immutable, @ToString, @Builder, and dozens ... 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. “Separate the construction of a complex object from its representation.” Design Patterns (1994), Builder intent Last Updated: July 2026 | Tested on: Groovy 5.0.6, 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 loses type safety. The groovy builder pattern via the @Builder annotation solves this ... Read More