Edd*_*Edd 54 java eclipse annotations compiler-warnings suppress-warnings
我@SuppressWarnings在eclipse中为代码获取了注释的编译器警告:
@Override
public boolean doSomething(@SuppressWarnings("unused") String whatever) throws AnException {
throw new AnException("I'm still in bed and can't do anything until I've had a shower!");
}
Run Code Online (Sandbox Code Playgroud)
在"未使用"一词下看起来像一个黄色的波浪线,在鼠标悬停时,我得到了工具提示Unnecessary @SuppressWarnings("unused").
我认为另一个开发人员被提示通过eclipse输入这些注释,我基本上被提示将它们删除.我如何配置eclipse以提示我将@SuppressWarnings注释放入而不是抱怨它?
如果有人想在这里评论最佳实践,那么这也是最受欢迎的.
Ósc*_*pez 56
在您的问题中的代码中,@SuppressWarnings("unused")注释是不必要的,因为该方法要么覆盖超类中的另一个方法,要么实现接口.即使你实际上没有使用whatever参数,也必须声明它,否则@Override注释会产生错误(如果你删除了参数,你将改变被覆盖方法的签名.)
在某些旧版本的Eclipse中,所显示的代码不会引起警告,但在最近的版本中它会发出警告.我相信这是一个有效的警告,我宁愿@SuppressWarnings("unused")在这种情况下删除它.
或者,如果您认为删除SuppressWarnings注释更正确:
窗口 - >首选项 - > Java - >编译器 - >错误/警告 - >不必要的代码 - >参数值未使用
并在覆盖和实现方法中选择忽略
在我的代码中,没有使用@SuppressWarnings("unused")定义3个方法的继承
此代码在Eclipse Juno(最新版本)中提供了"不必要的@SuppressWarnings("unused")",但是如果我删除@SuppressWarnings("unused"),我会在IntelliJ IDEA 11.1中收到"Constructor/Method is never used"警告. 3
这些方法不是直接在项目中使用,只有第三方产品Jackson,JAXB和GSON,所以IntelliJ是对的,我会说......
public class EmailUnsendable extends SkjemaError {
private NestedCommand command; // Can't be Command (interface) because of GSON!
@SuppressWarnings("unused") // Used by Jackson/JAXB/GSON
public EmailUnsendable() {
}
public EmailUnsendable(String referenceNumber, String stackTrace, NestedCommand command) {
super(referenceNumber, stackTrace);
this.command = command;
}
@SuppressWarnings("unused") // Used by Jackson/JAXB/GSON
public NestedCommand getCommand() {
return command;
}
@SuppressWarnings("unused") // Used by Jackson/JAXB/GSON
public void setCommand(NestedCommand command) {
this.command = command;
}
}
Run Code Online (Sandbox Code Playgroud)
我相信这是Eclipse中的一个错误.
| 归档时间: |
|
| 查看次数: |
76864 次 |
| 最近记录: |