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

  • 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.


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

    }

}

Tags:

Eclipse