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.