SAM type

Single Abstract Method type coercion with Groovy closures.

Groovy Interfaces – Contracts and Polymorphism with 10 Tested Examples

Learn how Groovy interfaces work with 10 tested examples. Covers interface declaration, default methods, SAM types, closure coercion, and polymorphism on Groovy 5.x. “Program to an interface, not an implementation. This is the single most important principle in object-oriented design.” Gang of Four, Design Patterns Last Updated: March 2026 | Tested on: Groovy 5.x, Java 17+ | Difficulty: Intermediate | Reading Time: 16 minutes Interfaces are the backbone of polymorphism in object-oriented programming. They define a contract – a set ... Read More

Groovy Functional Interfaces & SAM Types – Complete Guide with 12 Examples

Groovy functional interfaces and SAM type coercion with 12 examples. Covers closure conversion, Java interop, and custom SAM types. Tested on Groovy 5.x. “The best interface is the one you don’t have to think about – Groovy’s SAM coercion makes Java’s functional interfaces disappear into closures.” Brian Goetz, Java Concurrency in Practice Last Updated: March 2026 | Tested on: Groovy 5.x, Java 17+ | Difficulty: Intermediate to Advanced | Reading Time: 20 minutes If you’ve been writing Groovy alongside Java, ... Read More