Java / Lombok Interview questions
Why is Lombok's approach considered a "compiler hack" and what are the implications?
Lombok works by using internal, officially unsupported compiler APIs (from javac's and
Eclipse's own compiler internals) to directly rewrite a class's abstract syntax tree during compilation —
something the standard, documented annotation processing API doesn't actually permit (it only supports
generating entirely new, separate source files, not modifying existing ones). This is why the community often
describes it as "hacking" the compiler rather than simply "using" it as intended.
The practical implications:
- Compiler version sensitivity — a new major JDK release can change internal APIs Lombok depends on, requiring Lombok itself to be updated before it works with that JDK version.
- Tooling friction — any tool that processes source or bytecode without knowing about Lombok (some static analyzers, certain IDE features) can behave unexpectedly around Lombok-generated code.
- A degree of "magic" — some teams deliberately avoid Lombok specifically because they're uncomfortable relying on unofficial compiler internals for something as central as their class definitions.
More Related questions...