我有一个带有lombok的@Data
和@AllArgsConstructor(access = AccessLevel.PUBLIC)
的类:
@Data
@AllArgsConstructor(access = AccessLevel.PUBLIC)
public class ResponseVO implements Serializable {
private static final long serialVersionUID = 3461582576096529916L;
@JacksonXmlProperty(localName = "amount", isAttribute = true)
String amount;
}
当我使用构造函数时
new ResponseVO("22222");
将鼠标悬停在构造函数方法上时,我在工具提示内收到警告:
ResponseVO.ResponseVO(String amount)
@SuppressWarnings(value={"all"})
为什么添加此警告?没有@Data
它就会消失
类反编译没有任何警告:
public class ResponseVO implements Serializable {
private static final long serialVersionUID = 3461582576096529916L;
@JacksonXmlProperty(localName = "amount", isAttribute = true)
String amount;
public String getAmount() {
return this.amount;
}
public void setAmount(String amount) {
this.amount = amount;
}
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (!(o instanceof ResponseVO)) {
return false;
} else {
ResponseVO other = (ResponseVO) o;
if (!other.canEqual(this)) {
return false;
} else {
String this$amount = this.getAmount();
String other$amount = other.getAmount();
if (this$amount == null) {
if (other$amount != null) {
return false;
}
} else if (!this$amount.equals(other$amount)) {
return false;
}
return true;
}
}
}
protected boolean canEqual(Object other) {
return other instanceof ResponseVO;
}
public int hashCode() {
boolean PRIME = true;
byte result = 1;
String $amount = this.getAmount();
int result1 = result * 59 + ($amount == null ? 43 : $amount.hashCode());
return result1;
}
public String toString() {
return "ResponseVO(amount=" + this.getAmount() + ")";
}
public ResponseVO(String amount) {
this.amount = amount;
}
}
最佳答案
这不是警告,它是出现在所有类、方法等上的常规 Eclipse 工具提示。这些工具提示显示相应元素的 JavaDoc(在本例中为空),并列出该元素上的所有注释。
这就是为什么您会看到 @SuppressWarnings
:它由 Lombok 生成,以避免编译器对 Lombok 生成的代码发出警告。
问题仍然是为什么 Lombok 会生成这些抑制注释。
通常,Lombok 的代码不会产生任何警告。但是,新的 Java 语言或编译器版本可能会导致新类型的警告或新的弃用。因此,运行针对较新 Java 版本的未经调整的 Lombok 版本可能会产生警告。由于用户无法修复这些警告,因此这些警告将被抑制。
此外,添加 @SuppressWarnings("all")
还抑制非标准警告,例如来自代码 linter 或集成在 IntelliJ IDEA 等 IDE 中的代码分析。
关于java - Eclipse - 添加 lombok 的数据和构造函数时显示 @SuppressWarnings(value= {"all"}),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55155461/