Java中有效的@SuppressWarnings警告名称列表是什么?

在@SuppressWarnings("")中位于("")之间的位。


当前回答

我最喜欢的是IntelliJ中的@SuppressWarnings(“WeakerAccess”),当它认为你应该使用一个比你正在使用的更弱的访问修饰符时,它不会抱怨。为了支持测试,我们必须对一些方法进行公共访问,而@VisibleForTesting注释并不能阻止警告。

埃塔: “匿名者”在@MattCampbell链接的页面上评论了以下非常有用的注释:

You shouldn't need to use this list for the purpose you are describing. IntelliJ will add those SuppressWarnings for you automatically if you ask it to. It has been capable of doing this for as many releases back as I remember. Just go to the location where you have the warning and type Alt-Enter (or select it in the Inspections list if you are seeing it there). When the menu comes up, showing the warning and offering to fix it for you (e.g. if the warning is "Method may be static" then "make static" is IntellJ's offer to fix it for you), instead of selecting "enter", just use the right arrow button to access the submenu, which will have options like "Edit inspection profile setting" and so forth. At the bottom of this list will be options like "Suppress all inspections for class", "Suppress for class", "Suppress for method", and occasionally "Suppress for statement". You probably want whichever one of these appears last on the list. Selecting one of these will add a @SuppressWarnings annotation (or comment in some cases) to your code suppressing the warning in question. You won't need to guess at which annotation to add, because IntelliJ will choose based on the warning you selected.

其他回答

我最喜欢的是IntelliJ中的@SuppressWarnings(“WeakerAccess”),当它认为你应该使用一个比你正在使用的更弱的访问修饰符时,它不会抱怨。为了支持测试,我们必须对一些方法进行公共访问,而@VisibleForTesting注释并不能阻止警告。

埃塔: “匿名者”在@MattCampbell链接的页面上评论了以下非常有用的注释:

You shouldn't need to use this list for the purpose you are describing. IntelliJ will add those SuppressWarnings for you automatically if you ask it to. It has been capable of doing this for as many releases back as I remember. Just go to the location where you have the warning and type Alt-Enter (or select it in the Inspections list if you are seeing it there). When the menu comes up, showing the warning and offering to fix it for you (e.g. if the warning is "Method may be static" then "make static" is IntellJ's offer to fix it for you), instead of selecting "enter", just use the right arrow button to access the submenu, which will have options like "Edit inspection profile setting" and so forth. At the bottom of this list will be options like "Suppress all inspections for class", "Suppress for class", "Suppress for method", and occasionally "Suppress for statement". You probably want whichever one of these appears last on the list. Selecting one of these will add a @SuppressWarnings annotation (or comment in some cases) to your code suppressing the warning in question. You won't need to guess at which annotation to add, because IntelliJ will choose based on the warning you selected.

这似乎是一个更完整的列表,在那里我发现了一些特定于Android-Studio的警告,我在其他地方找不到(例如SynchronizeOnNonFinalField)

https://jazzy.id.au/2008/10/30/list_of_suppresswarnings_arguments.html

哦,现在SO的指导方针与SO的限制相反。 一方面,我应该复制列表,而不是只提供链接。 但另一方面,这将超过允许的最大字符数。所以让我们希望这个链接不会断裂。

如果你在使用SonarLint, 尝试上面的方法或类的整个鱿鱼串: @SuppressWarnings(“乌贼:S1172”)

允许所有值(未识别的值将被忽略)。已识别的列表是特定于编译器的。

在Java教程中,未选中和弃用被列为Java语言规范要求的两个警告,因此,它们对所有编译器都有效:

每个编译器警告都属于一个类别。Java语言规范列出了两个类别:弃用和未检查。

Java语言规范中定义它们的特定部分在不同版本之间是不一致的。在Java SE 8规范中,未选中和弃用被列为9.6.4.5节中的编译器警告。@SuppressWarnings和9.6.4.6 @Deprecated。

对于Sun的编译器,运行javac -X会给出该版本所能识别的所有值的列表。对于1.5.0_17,列表如下:

所有 弃用 无节制的 fallthrough 路径 串行 最后

我注意到IntelliJ中可以自动生成noinspection

确保你在声明之前没有计划@SuppressWarninigs 现在你可以自动生成特定的//noinspection,点击Alt+Enter当你有警告选择,然后使用右箭头键看到Suppress for…选项

当我想要压制来自IntelliJ的“switch有太少case标签”警告时,就结束在这里。我没有找到IntelliJ的@SuppressWarning支持的完整列表,但//noinspection为我做到了这一点。