How to call a super constructor in Lombok
Codemia Knowledge Hub ·
To call a superclass constructor with Lombok, write the subclass constructor explicitly and call super(...) inside it. Fields inherited from the parent are not covered by Lombok's generated constructors, so the explicit call is what wires them up. You can still put @Builder on that hand-written constructor to get a fluent API.
Lombok constructor annotations involved
@AllArgsConstructor: Generates a constructor with 1 parameter for each field in the class.@NoArgsConstructor: Generates a no-arguments constructor.@RequiredArgsConstructor: Generates a constructor for each final field.@Builder: Produces complex builder APIs for your classes.
Example: Employee extending Person
The base class has a regular constructor:
In the subclass, the constructor calls super(name, age) and then sets its own field:
@AllArgsConstructor generates a constructor for the fields declared in Employee only. Because Employee also inherits fields from Person, you need to call the superclass constructor explicitly in the constructor you define.
Calling super from a @Builder constructor
When constructors grow complex with many fields or optional parameters, put @Builder on the explicit constructor:
You get a fluent builder for Manager and keep control over the superclass constructor call.
Annotation reference
| Lombok Annotation | Description | Usage & Benefits |
@AllArgsConstructor | Generates all fields constructor | Perfect for straightforward classes with all fields as constructor args. |
@NoArgsConstructor | Generates no-arguments constructor | Useful when subclasses need a default constructor. |
@RequiredArgsConstructor | Generates constructor for final fields | Ensures all non-initialized final fields are set. |
@Builder | Offers a builder pattern implementation | Ideal for complex objects requiring conditional construction. |
Other constructor options
- Mixing annotations: You can combine Lombok annotations to cover different constructor needs.
- Custom logic: You can define your own constructor logic inside
@Builderor any annotated constructor. - Visibility control: Annotations like
@AllArgsConstructortake anaccessparameter to control constructor visibility.
Related reading
- How to capitalize the first letter of a String in Java?
- How to capitalize the first letter of word in a string using Java?
- How to capture a list of specific type with mockito
- How to catch an Exception from a thread
- How to catch deserialization error in Kafka-Spring?
- How to catch server error on Micronaut/Netty after client cancelled request
- How to chain non-blocking action in CompletionStage.exceptionally
- How to change a field name in JSON using Jackson
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.