@SuppressWarnings("unused")
我有一个与注释有关的基本问题。基本上,我想在我的类的声明部分中抑制未使用的代码块上的警告。我不希望在整个班级禁止未使用的警告。
目前,我正在这样做:
public class MyClass {
//Constants
private final String ACCEPT = "Yes";
@SuppressWarnings("unused")
private final String DENY = "No"; //Not currently used
private final String TENTATIVE = "Maybe";
@SuppressWarnings("unused")
private final String POSTPONE = "Later"; //Not currently used
//Variables
private int counter;
....
我发现上面的代码对于像这样随机抛出的注释有点混乱。我想做的是:
//Constants
@SuppressWarnings("unused")
{
private final String ACCEPT = "Yes";
private final String DENY = "No"; //Not currently used
private final String TENTATIVE = "Maybe";
private final String POSTPONE = "Later"; //Not currently used
}
//Variables
private int counter;
....
当然,这在 Java 中是非法的,因为不能像这样简单地制作一个块。这没什么大不了的,但我很好奇我是否错过了一个明显而优雅的解决方案。