简体   繁体   English

来自Java注释处理器的@SuppressWarnings

[英]@SuppressWarnings from a Java Annotation Processor

Java Annotation Processors can be used to issue info, warnings, or errors in Java code triggered by a variety of cases. Java注释处理器可用于在各种情况下触发Java代码中的信息,警告或错误。 Is there a way to suppress the info/warnings generically without directly implementing them in the Annotation Processor? 有没有一种方法可以在不直接在注释处理器中直接实现的情况下抑制信息/警告? Directly, what comes to mind is the @SupressWarnings annotation, but that doesn't seem to map to annotation processors as they require a name of what to suppress. 直接想到的是@SupressWarnings批注,但这似乎未映射到批注处理器,因为它们需要抑制的名称。

As a follow on question, would it be inappropriate to use the @SuppressWarnings annotation within an annotation processor to turn off info/warnings? 作为后续问题,在注释处理器中使用@SuppressWarnings注释来关闭信息/警告是否不合适?

The -Xlint compiler option can be used to disable warnings. -Xlint编译器选项可用于禁用警告。 You should be able to suppress annotation processor warnings with the option -Xlint:-processing . 您应该可以使用-Xlint:-processing选项禁止注释处理器警告。

There are many other types of warning that you can enable or disable separately this way without annotations. 您可以通过多种其他方式的警告(无需注释)分别启用或禁用。

The best way of course would be to avoid warnings at all, by fixing the code. 最好的方法当然是通过修复代码来完全避免警告。 Only add @SuppressWarnings when it is appropriate, like for example you know that an unchecked cast can't fail. 仅在@SuppressWarnings时添加@SuppressWarnings ,例如,您知道未经检查的强制转换不会失败。

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

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