javac无视@SuppressWarnings(“全部”)

时间:2012-12-05 18:21:22

标签: java annotations compiler-warnings

我目前有一个Enum,它有一个构造函数,可以取null并包含以下SuppressWarning批注:

@SuppressWarnings("all")
public enum TheEnum {
...
AN_ENUM_VALUE(null),
...
...
private TheEnum(TheEnum ... args) {
    if (args != null){
        ...
        ...
    }
...
}

我目前正在使用MyEclipse工作台10.6,它似乎很好地获取了注释。但是,在开发机器上进行编译时,我会收到与'TheEnum'类相关的警告。

奇怪的是,在项目中,整个地方都有@SuppressWarnings(“未经检查”),编译器设法选择这些并忽略它们。

由于遗留问题,我们必须使用JDK 1.5.0_17进行编译,但它看起来应该选择“全部”抑制:

[root@xxx]:/opt/jdk1.5.0_17/bin# ./javac -X
  ...
  -Xlint:{all,deprecation,unchecked,fallthrough,path,serial,finally,-deprecation,-   unchecked,-fallthrough,-path,-serial,-finally}Enable or disable specific warnings

关于我应该在哪里看到为什么'all'被忽略的任何建议?

1 个答案:

答案 0 :(得分:0)

首先不要使用它。

@SuppressWarnings("all")

说,你做错了什么。我会尽快与任何开发此类代码的开发人员取消合同。警告是有原因的,并且一揽子忽略说“我不关心我的代码是否真的有效”,就像其他任何东西一样。这与编写单元测试有些相反:全局禁用编译器检查。

http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html#options判断“所有”可能是日食延伸。 Sun / Oracle Java 6编译器可能仅支持以下值:uncheckedpathserialfinallyfallthroughdeprecation。< / p>

相关问题