Why required args constructor does not support generation for child classes?

50 views
Skip to first unread message

Volodymyr Kushnir

unread,
Apr 30, 2025, 12:05:19 PMApr 30
to Project Lombok
Hello there,

It seems required args constructor is not supported for child classes. I belieave it works like that because parent can have multiple constructors and this is done to avoid complex lookup logic. Prepared example to reproduce this case:

```
@Getter
@RequiredArgsConstructor
public class A {

    private final String a;

}

@Getter
@RequiredArgsConstructor // Implicit super constructor A() is undefined. Must explicitly invoke another constructor
public class B extends A {

    private final String b;

}

```

Sure there might be several constructors in the parent class, but if parent class has required arg constructor generated by Lombok we might use this as our default option.
It is possible to generate required arg constructor for class 'B' which has all parameters which should be passed to 'A' constructor + parameters which are final in 'B' class.

This will significantly improve usability of required arg constructors for classes which need inheritance (mostly components for dependency injection).

Thanks,
Volodymyr
Reply all
Reply to author
Forward
0 new messages