AST

Abstract Syntax Tree transformations in Groovy.

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

Groovy AST Transformations – Compile-Time Code Generation with 10+ Examples

Groovy AST transformations for compile-time code generation. 10+ examples covering @ToString, @EqualsAndHashCode, @Canonical, @Delegate, and custom ASTs. “The best code is code you never write. AST transformations generate boilerplate at compile time so you can focus on what matters.” Groovy Metaprogramming Philosophy Last Updated: March 2026 | Tested on: Groovy 5.x, Java 17+ | Difficulty: Intermediate to Advanced | Reading Time: 20 minutes Every developer knows the pain of writing toString(), equals(), hashCode(), constructors, and getters/setters for every class. It’s ... Read More

Groovy @Immutable Annotation – Create Immutable Objects with 10+ Examples

Groovy immutable objects with @Immutable annotation to create immutable objects with 10+ examples. Defensive copies, known types, copyWith, and thread-safe value objects. “Immutable objects are always thread-safe. If you can make your objects immutable, you eliminate an entire category of concurrency bugs.” Effective Java, Joshua Bloch Last Updated: March 2026 | Tested on: Groovy 5.x, Java 17+ | Difficulty: Intermediate | Reading Time: 18 minutes Creating truly immutable objects in Java requires a checklist: final class, final private fields, no ... Read More