Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing warning for unused method parameter?

I am using Eclipse v3.5.

In previous Eclipse versions i remember if i have defined a method with a parameter and didn't use it internally a warning appears, like this :

public void myMethod( int x ) {
  // Didn't use x here so a warning appears at the x parameter.
}

But in v3.5 i do not see this warning. How can i enable it in Eclipse ?

like image 313
Brad Avatar asked Apr 26 '10 16:04

Brad


People also ask

How do I get rid of unused variable warning?

Solution: If variable <variable_name> or function <function_name> is not used, it can be removed. If it is only used sometimes, you can use __attribute__((unused)) . This attribute suppresses these warnings.

How do I stop the warning on Kotlin?

You can also use @Suppress in Kotlin or @SuppressWarnings in Java. To suppress a lint warning with a comment, add a //noinspection id comment on the line before the statement with the error.

What is unused parameter?

Reports the parameters that are considered unused in the following cases: The parameter is passed by value, and the value is not used anywhere or is overwritten immediately. The parameter is passed by reference, and the reference is not used anywhere or is overwritten immediately.


1 Answers

See

Window / Preferences / Java / Compiler / ErrorsWarnings / Unnecessary Code / Value of parameter is not used

In old versions (before Eclipse Juno?) the setting was called "Parameter is never read".

Note:

If there is a valid reason for not using a parameter (e.g. it is used via reflection), you can suppress the warning by annotating the method with

@SuppressWarnings("unused")
like image 123
sleske Avatar answered Oct 13 '22 21:10

sleske