简体   繁体   中英

Suppress the “unused” warning for a method, but not the variables within it

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.

As far as I know, there is no way to scope SurpressWarning to the method declaration only.

This leaves you with these possibilities:

  • Increase the visibility of the method to package or protected. Slightly increasing visibility has the added benefit that it becomes available to unit tests.
  • Create a dummy method which has call to the unused methods. (This feels really ugly).

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' !)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM