Skip to content
Advertisement

Why is Lombok @Builder not compatible with this constructor?

I have this simple code:

JavaScript

First I was using only the @Builder Lombok annotation and everything was fine. But I added the constructor and the code does not compile any more. The error is:

JavaScript

So I have two questions:

  1. Why is Lombok @Builder not compatible with this constructor?
  2. How do I make the code compile taking into account that I need both the builder and the constructor?

Advertisement

Answer

You can either add an @AllArgsConstructor annotation, because

@Builder generates an all-args constructor iff there are no other constructors defined.

(Quotting @Andrew Tobilko)

Or set an attribute to @Builder : @Builder(toBuilder = true) This give you the functionality of a copy constructor.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement