Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide sidebar warning "The value of the local variable is not used" in Eclipse?

Tags:

eclipse

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?

like image 915
sonicboom Avatar asked Dec 30 '12 14:12

sonicboom


2 Answers

  • Windows > preferences
  • Java > Compiler > Error/Warnings
  • Open "Unnecessary code" group
  • change "Value of local variable is not used" from "Warning" to "Ignore"

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.

like image 83
giampaolo Avatar answered Nov 11 '22 18:11

giampaolo


@SuppressWarnings("unused")

Add the above line of code before main() it will suppress all the warning of this kind in the whole program. for example

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

    }

}
like image 30
Rakesh Avatar answered Nov 11 '22 18:11

Rakesh