本文介绍了在使用Lombok构建Maven的过程中,已经在类中定义了Image()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码在使用Maven进行构建时,在@NoArgsConstructor
行上导致编译错误(Image() is already defined in class
).
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?
龙目岛版本是1.16.22.
Lombok version is 1.16.22.
推荐答案
由于Lombok v1.16.22中的错误,在类上同时指定@Data
和@NoArgsConstructor
会触发错误.主要版本v1.18.0中已修复此问题.
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.
在龙目岛变更日志中,我们在v1.18.0下找到以下内容:
In the Lombok changelog, we find the following under v1.18.0:
这篇关于在使用Lombok构建Maven的过程中,已经在类中定义了Image()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!