Search code examples
springspring-bootspring-data-jpalombokspring-annotations

Lombok: Generate 2 constructors with specified fields


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?


Solution

  • 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