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?

2
  • 1
    related question stackoverflow.com/questions/23761242/… you can use builder(s) instead constructor(s) Commented Oct 31, 2021 at 13:33
  • So sadly the only way is Builder and I can't do it through annotation I see :(( Commented Oct 31, 2021 at 13:35

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.