如何在 Eclipse 中隐藏侧边栏警告“未使用局部变量的值”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14091613/
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
How to hide sidebar warning "The value of the local variable is not used" in Eclipse?
提问by sonicboom
The "The value of the local variable is not used" warning is really annoying as it hide breakpoints in the sidebar. The variable in question also gets underlined to highlight this warning so the sidebar icon is fairly redundant.
“未使用局部变量的值”警告真的很烦人,因为它隐藏了侧边栏中的断点。有问题的变量也带有下划线以突出显示此警告,因此侧边栏图标相当多余。
So is there any way to hide this warning in the sidebar?
那么有没有办法在侧边栏中隐藏这个警告?
回答by giampaolo
- Windows> preferences
- Java> Compiler> Error/Warnings
- Open "Unnecessary code"group
- change "Value of local variable is not used"from "Warning"to "Ignore"
- 窗口>首选项
- Java>编译器>错误/警告
- 打开“不需要的代码”组
- 将“未使用局部变量的值”从“警告”更改为“忽略”
It will require a new build and it's done.
这将需要一个新的构建,它已经完成。
Of course, you must aware that you are ignoring that option and potentially increasing memory consumption and leaving clutter in your code.
当然,您必须意识到您忽略了该选项并可能增加内存消耗并在您的代码中留下混乱。
回答by Rakesh
@SuppressWarnings("unused")
@SuppressWarnings("未使用")
Add the above line of code before main() it will suppress all the warning of this kind in the whole program. for example
在 main() 之前添加上面的代码行,它将在整个程序中抑制所有此类警告。例如
public class CLineInput
{
@SuppressWarnings("unused")
public static void main(String[] args)
{
You can also add this exactly above the declaration of the variable which is creating the warning, this will work only for the warning of that particular variable not for the whole program. for example
您还可以在创建警告的变量声明的正上方添加它,这仅适用于该特定变量的警告,而不适用于整个程序。例如
public class Error4
{
public static void main(String[] args)
{
int a[] = {5,10};
int b = 5;
try
{
@SuppressWarnings("unused") // It will hide the warning, The value of the local variable x is not used.
int x = a[2] / b - a[1];
}
catch (ArithmeticException e)
{
System.out.println ("Division by zero");
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array index error");
}
catch(ArrayStoreException e)
{
System.out.println("Wrong data type");
}
int y = a[1] / a[0];
System.out.println("y = " + y);
}
}