eclipse 显示未使用的方法参数的警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2715178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Showing warning for unused method parameter?
提问by Brad
I am using Eclipse v3.5.
我正在使用 Eclipse v3.5。
In previous Eclipse versions i remember if i have defined a method with a parameter and didn't use it internally a warning appears, like this :
在以前的 Eclipse 版本中,我记得如果我定义了一个带有参数的方法并且没有在内部使用它,则会出现警告,如下所示:
public void myMethod( int x ) {
// Didn't use x here so a warning appears at the x parameter.
}
But in v3.5 i do not see this warning. How can i enable it in Eclipse ?
但是在 v3.5 中我没有看到这个警告。如何在 Eclipse 中启用它?
回答by sleske
See
看
Window / Preferences / Java / Compiler / ErrorsWarnings / Unnecessary Code / Value of parameter is not used
Window / Preferences / Java / Compiler / ErrorsWarnings / Unnecessary Code / Value of parameter is not used
In old versions (before Eclipse Juno?) the setting was called "Parameter is never read".
在旧版本中(在 Eclipse Juno 之前?),该设置被称为"Parameter is never read"。
Note:
笔记:
If there is a valid reason for not using a parameter (e.g. it is used via reflection), you can suppress the warning by annotating the method with
如果有一个不使用参数的正当理由(例如它通过反射使用),你可以通过注释方法来抑制警告
@SuppressWarnings("unused")