Feature Request: Support superclass constructor generation in @RequiredArgsConstructor

9 views
Skip to first unread message

Dhiraj Shinde

unread,
Jul 29, 2026, 3:14:49 AM (12 days ago) Jul 29
to Project Lombok

Hi Lombok Team,

First, thank you for the excellent work on Lombok.

While using @RequiredArgsConstructor in an inheritance hierarchy, I noticed that the annotation only considers fields declared in the annotated class. If the superclass exposes only a parameterised constructor, Lombok generates a constructor that implicitly relies on super(), causing a compilation error because no no-argument constructor exists.

I understand this is the current intended behaviour, but I would like to propose an optional enhancement.

An opt-in feature such as @RequiredArgsConstructor(callSuper = true) could inspect the direct superclass constructor and generate the corresponding super(...) invocation when there is exactly one unambiguous constructor. If multiple superclass constructors exist, Lombok could emit a compilation error requesting that the constructor be written manually.

Example:
abstract class AppController {

    protected final HttpServletRequest request;

    protected AppController(HttpServletRequest request) {
        this.request = request;
    }
}

@RequiredArgsConstructor(callSuper = true)
class ClinicController extends AppController {
    private final ClinicService clinicService;
}

Generated:
public ClinicController(HttpServletRequest request,
                        ClinicService clinicService) {
    super(request);
    this.clinicService = clinicService;
}

I believe this would reduce boilerplate while remaining backwards compatible because it would be an explicit opt-in feature.

Thank you for considering the suggestion.

Reinier Zwitserloot

unread,
Jul 29, 2026, 7:54:17 AM (12 days ago) Jul 29
to Project Lombok
In order to create such a feature, lombok would need to know the signatures of the content of the superclass.

And then we would generate code that... changes the signatures of _this_ class.

Thus, a chicken and egg problem: The compiler goes through a bunch of steps, and one of them is 'for all types that we are about to load or compile, figure out all the signatures'. And now this step is a convoluted multi-phase process, which is very difficult to maintain.

Which is why we don't do it. It'd be a great feature but it's extremely complicated to provide.

Reply all
Reply to author
Forward
0 new messages