Suppress an "unused" warning for a method, but not variables inside it

As the title says, how can I suppress a warning only for a method? Is it possible?

A bit of background: I use the JavaScript bridge and it connects to these methods, so I would like to suppress this warning. What I would like to avoid is an annotation warning warnings for unused variables inside a method. I am currently using @SuppressWarnings("unused") before declaring a method, but this suppresses everything.

+8
java suppress-warnings
source share
2 answers

As far as I know, there is no way to cover SurpressWarning just for declaring a method.

This gives you the following options:

  • Increase the visibility of the method for packaging or protection. A small increase in visibility has the added benefit of being available for unit tests.
  • Create a dummy method that calls unused methods. (It seems very ugly).
+3
source share

In eclipse, if we install the following

Settings β†’ Java β†’ Error / Warnings β†’ Unnecessary code β†’ Local variable is never read ==> Error

then even when using the @SuppressWarnings ("unused") method, the method only suppresses a warning about the unused method. An unused variable is displayed as Error.

(I know you wanted them to be β€œwarnings,” but all I can think of is β€œmistakes”!)

+3
source share

All Articles