Home > Back-end >  Lombok: Generate 2 constructors with specified fields
Lombok: Generate 2 constructors with specified fields

Time:10-31

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?

CodePudding user response:

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

  • Related