java - Eclipse - 添加 lombok 的数据和构造函数时显示 @SuppressWarnings(value= {"all"})

标签 java eclipse lombok suppress-warnings

我有一个带有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/

相关文章:

java - android unicode 到可读字符串

Eclipse Luna 4.4 全屏

java - BIRT - 我应该将图像放在哪里,以便可以预览并部署到 Web 应用程序中

java - Lombok @NonNull 与 Validate.notNull

java - Lombok 项目 - 地理围栏类型的方法未定义

java - 未找到处理类文件中 Intent 的 Activity

java - 如何使用现有对象作为构造函数参数在 spring 中实例化 bean

java - JAXB、带有 @XmlID 注释的 XML mashal

java - 从 Eclipse 插件运行 JUnit 测试并访问结果

java - 如何更改 Lombok 的 @ToString 生成的方法的输出?