Image() is already defined in class during Maven build using Lombok

Alex Smith :

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.

Tomasz Linkowski :

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=68605&siteId=1