1

So I want to generate two constructors using the

@RequiredArgsConstructor
class Foo {
    @NonNull
    private String a;
     @NonNull
    private double b;
    private int c;
}

My class would be generating a constructer with a & b. But what If I also want to generate a second contructor with b & c? Is there any solution using annnotations?

Compte Gmail
  • 137
  • 3
  • 8
  • 1
    related question https://stackoverflow.com/questions/23761242/java-lombok-omitting-one-field-in-allargsconstructor you can use builder(s) instead constructor(s) – Ori Marko Oct 31 '21 at 13:33
  • So sadly the only way is Builder and I can't do it through annotation I see :(( – Compte Gmail Oct 31 '21 at 13:35

1 Answers1

2

Due to Lombok documentation, you can't do this. in another language you can not have different constructors with combinations of some fields. a better solution is to use @Builder

Mehdi Varse
  • 271
  • 1
  • 15