Groovy’s @AutoImplement annotation generates placeholder implementations for missing abstract methods inherited from a superclass or required by an interface. Add it to a class to satisfy those contracts at compile time; for visible, editable stubs instead, use IntelliJ IDEA’s Implement methods action.
What @AutoImplement does
Introduced in Groovy 2.5.0, @groovy.transform.AutoImplement is an AST transformation that supplies dummy implementations for abstract methods found in superclasses and interfaces. The generated methods are included in the compiled bytecode, so the class satisfies those method contracts. See the Apache Groovy API documentation.
An interface defines a contract that a conforming class must meet; @AutoImplement can fill in missing methods for that contract as well as abstract methods inherited from a superclass. It leaves methods you have already implemented unchanged.
Apply the annotation to a class
Import the annotation, then place it above the class declaration:
import groovy.transform.AutoImplement
@AutoImplement
class DefaultCourseCreator implements Creator<Course> { }
It also works when a class both extends an abstract class and implements an interface:
@AutoImplement
class MyNames extends AbstractList<String> implements Closeable { }
Groovy generates implementations for the required methods that the class has not supplied. The class can still provide its own implementations for methods whose behavior it already knows.
What generated methods return
By default, generated methods are deliberately minimal placeholders, not functional business logic. Void methods have empty bodies; methods returning objects return null; a boolean method returns false; and an int method returns 0. For example, the official Groovy documentation shows generated get returning null, addAll returning false, size returning 0, and close doing nothing.
These defaults can make scaffolding or incremental implementation compile, but calls may silently produce meaningless results. Replace the generated behavior with real logic before relying on those methods, or configure a failure strategy so an unintended call is visible.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallRank #3
Choose explicit fallback behavior
Throw a selected exception
Set exception and, optionally, message to make generated methods throw when called:
@AutoImplement(exception = UnsupportedOperationException, message = 'Not supported')
class MyNames extends AbstractList<String> implements Closeable { }
This is useful when the class needs to meet a contract for compilation but a call to an unimplemented operation should fail clearly.
Rank #4
- Used Book in Good Condition
Provide a method body with code
Use the code closure when generated methods should share a custom body:
@AutoImplement(code = { throw new UnsupportedOperationException('Should never be called') })
class MyNames extends AbstractList<String> implements Closeable { }
The closure’s statements become the generated method body. Existing custom methods are preserved rather than replaced, so a class can combine real implementations with generated fallbacks. The mrhaki example and explanation describes this behavior.
Best Value
Use IntelliJ IDEA to generate editable stubs
In IntelliJ IDEA 2026.2, use Code | Implement methods or press Ctrl+I. You can also choose Generate (Alt+Insert) → Implement methods, or invoke Alt+Enter. The dialog lists methods that are not already implemented or are inaccessible; select the methods to add. IntelliJ can copy JavaDoc, and the generated method bodies follow an editable code template with default return values. See JetBrains’ Implementing methods documentation.
IDE-generated implementations are written into the source file, where you can review and edit them directly. This differs from the annotation, which generates placeholder methods through Groovy’s compile-time AST transformation.
Choose the approach that fits the work
| Consideration | @AutoImplement |
IntelliJ IDEA |
|---|---|---|
| When implementations are created | At compile time through an AST transformation. | When you invoke the IDE action; methods are generated in the source file. |
| Are stubs visible in source? | No; the annotation generates them for compiled bytecode. | Yes; the generated methods are editable source code. |
| How fallback behavior is chosen | Default type-based placeholder returns, or specify exception/message or a code closure. |
Generated bodies use the IDE’s editable code template with default return values. |
| What happens to existing implementations? | Existing custom methods are not overwritten. | The dialog lists methods that are not already implemented or are inaccessible. |
| Reviewing and replacing behavior | Replace generated fallbacks by writing real methods in the class; generated bodies are not individually present in source. | Review and edit the generated method bodies directly in the source file. |
Choose @AutoImplement when compile-time generation of consistent placeholders is intentional. Choose IntelliJ’s action when you want each stub visible and editable in source. In either case, treat default return values as scaffolding rather than an implementation of the contract’s real behavior.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitches

