简体   繁体   English

抑制方法的“未使用”警告,但不抑制其中的变量

[英]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. 一点背景:我正在使用JavaScript桥接器并且它挂钩到这些方法,所以我想抑制这个警告。 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. 我目前只是在方法声明之前使用@SuppressWarnings("unused") ,但这会抑制一切。

As far as I know, there is no way to scope SurpressWarning to the method declaration only. 据我所知,没有办法将SurpressWarning的范围仅限于方法声明。

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 在eclipse中,如果我们设置以下内容

Preferences -> Java -> Error/Warnings -> Unnecessary code -> Local variable is never read ==> Error 首选项 - > Java - >错误/警告 - >不必要的代码 - >永远不会读取局部变量==>错误

then, even when the @SuppressWarnings("unused") is applied on the method it only suppresses unused method warning. 那么,即使在方法上应用了@SuppressWarnings(“unused”),它也只会抑制未使用的方法警告。 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' !) (我知道,你希望他们成为'警告',但我能想到的只是'错误'!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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