Eclipse - 在添加lombok的Data和Constructor时显示@SuppressWarnings(value = {“all”})

问题描述 投票:0回答:1

我有一个班级与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;
    }
}
java eclipse lombok suppress-warnings
1个回答
1
投票

这不是警告,它是常规Eclipse工具提示,它出现在所有类,方法等上。这些工具提示显示了相应元素的JavaDoc(在本例中为空),并列出了元素上的所有注释。这就是为什么你看到@SuppressWarnings:它是由Lombok生成的,以避免编译器发出对Lombok生成的代码的警告。

问题仍然是龙目岛为什么会产生这些抑制注释。通常,Lombok的代码不会产生任何警告。但是,新的Java语言或编译器版本可能会导致新类型的警告或新的弃用。因此,针对较新的Java版本运行不适应的Lombok版本可能会产生警告。由于用户无法修复这些警告,因此会禁止这些警告。此外,添加@SuppressWarnings("all")还可以抑制非标准警告,例如来自代码链接或集成在像IntelliJ IDEA这样的IDE中的代码分析。

© www.soinside.com 2019 - 2024. All rights reserved.