如何在Eclipse中隐藏侧边栏警告"未使用局部变量的值"?

son*_*oom 6 eclipse

"未使用局部变量的值"警告实际上很烦人,因为它隐藏了侧边栏中的断点.有问题的变量也会加下划线以突出显示此警告,因此侧边栏图标相当多余.

那么有没有办法在侧边栏中隐藏这个警告?

gia*_*olo 10

  • Windows > 首选项
  • Java > 编译器 > 错误/警告
  • 打开"不必要的代码"
  • 更改"不使用局部变量的值""警告""忽略"

它需要一个新的构建并且已经完成.

当然,您必须意识到您忽略了该选项并可能增加内存消耗并在代码中留下混乱.


Rak*_*esh 5

@SuppressWarnings( "未使用")

在main()之前添加上面的代码行,它将在整个程序中禁止这种类型的所有警告.例如

public class CLineInput 
{
    @SuppressWarnings("unused")
    public static void main(String[] args) 
    {
Run Code Online (Sandbox Code Playgroud)

您也可以将此添加到正在创建警告的变量的声明之上,这仅适用于特定变量的警告,而不是整个程序的警告.例如

   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);

    }

}
Run Code Online (Sandbox Code Playgroud)