As the title asks, how do I suppress the warning for just the method? Is this possible?
A little background: I'm using a JavaScript bridge and it hooks into these methods, so I'd like to suppress this warning. What I would like to avoid is the annotation preventing warnings for unused variables within the method. I'm currently just using the @SuppressWarnings("unused")
before the method declaration, but this suppresses everything.
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.
To suppress the warning, one can simply name the variable with an underscore ('_') alone. Python treats it as an unused variable and ignores it without giving the warning message.
The @SuppressWarnings annotation disables certain compiler warnings. In this case, the warning about deprecated code ( "deprecation" ) and unused local variables or unused private methods ( "unused" ).
Use of @SuppressWarnings is to suppress or ignore warnings coming from the compiler, i.e., the compiler will ignore warnings if any for that piece of code.
As far as I know, there is no way to scope SurpressWarning to the method declaration only.
This leaves you with these possibilities:
In eclipse, If we set the following
Preferences -> Java -> Error/Warnings -> Unnecessary code -> Local variable is never read ==> Error
then, even when the @SuppressWarnings("unused") is applied on the method it only suppresses unused method warning. The unused variable is shown as an Error.
(I know, you wanted them to be 'warnings' but all I can come up with are 'errors' !)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With