A local variable that is never read is useless.

As a matter of good practice, there should be no unused or useless code. It makes the program more difficult to understand and maintain, and can waste a programmer's time.

This rule applies to variables that are never used as well as variables that are only written to but never read. In both cases, ensure that no operations are missing that would use the local variable. If appropriate, simply remove the declaration. However, if the variable is written to, ensure that any side-effects in the assignments are retained. (For further details, see the example.)

In the following example, the local variable oldQuantity is assigned a value but never read. In the fixed version of the example, the variable is removed but the call to items.put in the assignment is retained.

  • Help - Eclipse Platform: Java Compiler Errors/Warnings Preferences.