if
语句上方的 SuppressWarnings
注释有什么问题?带有 Sun JDK 6 的 Eclipse 提供了两种语法错误描述,既没有帮助又难以理解,如注释所示。
class TestDeadCode
{
//@SuppressWarnings("all")
public static void main(String[] args)
{
@SuppressWarnings("all") // syntax errors: insert enum body, insert enum id
if ((Constants.flag0) && (Constants.flag1))
System.out.println("hello\n");
}
}
interface Constants
{
boolean flag0 = false;
boolean flag1 = false;
}
最佳答案
只能注释类、方法、变量声明、参数和包。因此,您不能在 if 语句中使用 SuppressWarnings("all")。
要解决此问题,您只需执行以下操作即可。
@SuppressWarnings("all")
boolean flag = Constants.flag0 && Constants.flag1;
if (flag) {
System.out.println("hello\n");
}
目前还没有 SuppressWarnings("Dead code")。
http://docs.oracle.com/javase/7/docs/api/java/lang/SuppressWarnings.html http://pmd.sourceforge.net/suppressing.html
关于java - 来自 Eclipse 的 SuppressWarnings "all"投诉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8860494/