Java Lombok Omitting one field in AllArgsConstructor?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If you want Lombok to generate a constructor but skip one specific field, @AllArgsConstructor is usually the wrong annotation. Its job is exactly what the name says: generate a constructor for all non-static fields, so there is no built-in "exclude this one field" switch for arbitrary omission.
What @AllArgsConstructor Really Does
@AllArgsConstructor includes every instance field except static fields. That means code like this:
generates a constructor equivalent to:
If your requirement is "generate a constructor but leave out email," then @AllArgsConstructor is not the right match.
The Usual Fix: Use @RequiredArgsConstructor
If only some fields should be in the constructor, mark those fields as final or @NonNull and use @RequiredArgsConstructor.
Now Lombok generates a constructor only for the required fields, and email is left out because it is not required.
This is usually the cleanest Lombok-native solution when some fields are constructor-required and others are optional.
Another Fix: Write the Constructor Yourself
If the inclusion rule is more specific than Lombok's standard constructor annotations can express, just write the constructor manually.
This is often better than fighting the annotation model. Lombok is useful when it makes the code clearer, not when it forces awkward workarounds.
When @Builder Is a Better Fit
If the class has many optional fields, a builder is often more readable than any constructor variant.
Then callers can choose what to set:
That is especially useful when omitting fields is normal rather than exceptional.
What Does Not Solve It
Annotations such as @ConstructorProperties do not change what Lombok decides to include in @AllArgsConstructor. They may affect metadata or explicit constructors you write yourself, but they do not turn @AllArgsConstructor into a selective constructor generator.
So the answer is not "tell @AllArgsConstructor to skip one field." The answer is usually:
- use
@RequiredArgsConstructor - or use
@Builder - or write the constructor manually
That is a good example of a broader Lombok rule: choose the annotation that matches the object model you actually want, instead of trying to bend a convenience annotation into a custom code generator.
Common Pitfalls
- Expecting
@AllArgsConstructorto support arbitrary field exclusion. - Adding annotations that affect reflection metadata but not Lombok constructor generation.
- Using
@AllArgsConstructorwhen the real model is "some fields required, some optional." - Forcing a Lombok solution when a handwritten constructor would be clearer.
- Forgetting that static fields are already excluded, which can cause confusion when testing examples.
Summary
- '
@AllArgsConstructorincludes all non-static instance fields by design.' - It does not provide a general "omit this one field" option.
- Use
@RequiredArgsConstructorwhen only required fields belong in the constructor. - Use
@Builderwhen optional fields are common. - When Lombok stops matching the design cleanly, write the constructor yourself.
Related reading
- Java machine learning library for commercial use?
- Java memory model - volatile and x86
- Java merge 2 collections in O1
- Java method with return type compiles without return statement
- Java multi-threading Safe Publication
- Java Multiple class declarations in one file
- Java Multiple Inheritance
- Java Multithreading for IVRS with GSM Modem rxtx playing voice file making event listener stop working

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.