The below code is causing a compilation error (Image() is already defined in class
) on the line with @NoArgsConstructor
when building with Maven.
import lombok.Data;
import lombok.NoArgsConstructor;
// tag::code[]
@Data
@NoArgsConstructor
public class Image {
private int id;
private String name;
public Image(int id, String name) {
this.id = id;
this.name = name;
}
}
What is causing this problem and how can I fix it?
EDIT: Lombok version is 1.16.22.
Due to a bug in Lombok v1.16.22, specifying both @Data
and @NoArgsConstructor
on a class triggered an error. This has been fixed in major release v1.18.0.
In the Lombok changelog, we find the following under v1.18.0:
BUGFIX: Do not generate a private no-args constructor if that breaks the code. Issue #1703, Issue #1704, Issue #1712
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With