Java忽略警告注解@SuppressWarnings

Java忽略警告注解@SuppressWarnings忽略全部类型的警告 SuppressWarn all 忽略未检查的转化 例如集合没有指定类型的警告 SuppressWarn unchecked 忽略未使用的变量的警告 SuppressWarn unused 忽略与使用 Closeable 类型资源相关的警告 SuppressWarn resource 忽略在类路径 原文件路径中有不存在的路径的警告 SuppressWarn

 

// 忽略全部类型的警告 @SuppressWarnings("all")    // 忽略未检查的转化,例如集合没有指定类型的警告 @SuppressWarnings("unchecked")   // 忽略未使用的变量的警告 @SuppressWarnings("unused")  // 忽略与使用Closeable类型资源相关的警告 @SuppressWarnings("resource")   // 忽略在类路径,原文件路径中有不存在的路径的警告 @SuppressWarnings("path")    // 忽略使用了某些不赞成使用的类和方法的警告 @SuppressWarnings("deprecation") // 忽略switch语句执行到底没有break关键字的警告 @SuppressWarnings("fallthrough") // 忽略某类实现Serializable,但是没有定义serialVersionUID的警告 @SuppressWarnings("serial")  // 忽略没有传递带有泛型的参数的警告 @SuppressWarnings("rawtypes") 

源码 

package java.lang; import java.lang.annotation.*; import static java.lang.annotation.ElementType.*; / * Indicates that the named compiler warnings should be suppressed in the * annotated element (and in all program elements contained in the annotated * element). Note that the set of warnings suppressed in a given element is * a superset of the warnings suppressed in all containing elements. For * example, if you annotate a class to suppress one warning and annotate a * method to suppress another, both warnings will be suppressed in the method. * * 

As a matter of style, programmers should always use this annotation * on the most deeply nested element where it is effective. If you want to * suppress a warning in a particular method, you should annotate that * method rather than its class. * * @author Josh Bloch * @since 1.5 * @jls 4.8 Raw Types * @jls 4.12.2 Variables of Reference Type * @jls 5.1.9 Unchecked Conversion * @jls 5.5.2 Checked Casts and Unchecked Casts * @jls 9.6.3.5 @SuppressWarnings */ @Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE}) @Retention(RetentionPolicy.SOURCE) public @interface SuppressWarnings { / * The set of warnings that are to be suppressed by the compiler in the * annotated element. Duplicate names are permitted. The second and * successive occurrences of a name are ignored. The presence of * unrecognized warning names is not an error: Compilers must * ignore any warning names they do not recognize. They are, however, * free to emit a warning if an annotation contains an unrecognized * warning name. * *

The string {@code "unchecked"} is used to suppress * unchecked warnings. Compiler vendors should document the * additional warning names they support in conjunction with this * annotation type. They are encouraged to cooperate to ensure * that the same names work across multiple compilers. * @return the set of warnings to be suppressed */ String[] value(); }

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/216698.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月18日 上午11:16
下一篇 2026年3月18日 上午11:16


相关推荐

  • html css is图片,isbackground

    html css is图片,isbackgroundisbackground有何作用首先不是为了多线程而多线程,多线程会极大的带来额外的出错的几率。C#中第一个打开窗口的线程是主线程,也是处理UI的线程,最好保持这个线程通畅,即不要有阻塞操作,如Thread.Sleep(10);等这样是不好的。耗时的线程需要打开新的线程来操作。c#可以使用多少个Thread.IsBackground=true我现在有一个程序,有UDP/TCP/US…

    2022年10月16日
    3
  • SAP License:实例讲解SAP与金税接口

    SAP License:实例讲解SAP与金税接口SAP与金税接口的问题很多人问我。今天我通过实例给大家讲解一下。步骤一:与金税公司取得联系,他们会给一个Word文档,里面描述金税系统的字段描述。步骤二:与金税公司签订合同,取得接口安装程序,现在有EXCEL接口和文本接口两种,建议购买EXcel接口,同时金税公司会提供U盘加密卡。步骤三:在SAP系统中做如下配置:销售和分销-基本功能-输出控制-输出确定-使用条件技术的输出确认-维护开票单据的输出确定-维护输出类型VV31双击行项目设置打印机(图片插入不进来)步骤四:Abap开发程序。

    2022年5月30日
    66
  • flask框架总结(一)

    flask框架总结(一)正如总所周知的一样 Flask 是一个使用 Python 编写的轻量级 Web 应用框架 轻巧页就意味着他比较简洁 不过见到的 MTV 框架还是有的 MVC 但是最重要的还是他的可扩展性很强 对比与 Django 框架呢 他的灵活度就很高了 可以自己一些设计代码框架 他比较适合一些 分层比较少 逻辑不怎么复杂的 web 项目 如果开发成本低的话 那就更适合了 现在就总结下他的一些功能 现在搭建个 fl

    2026年3月26日
    2
  • 电脑九大常用的网络命令 ,很实用!

    电脑九大常用的网络命令 ,很实用!ping 是个使用频率极高的实用程序 主要用于确定网络的连通性 这对确定网络是否正确连接 以及网络连接的状况十分有用 简单的说 ping 就是一个测试程序 如果 ping 运行正确 大体上就可以排除网络访问层 网卡 Modem 的输入输出线路 电缆和路由器等存在的故障 从而缩小问题的范围 ping 能够以毫秒为单位显示发送请求到返回应答之间的时间量 如果应答时间短 表示数据报不必通过太多的路由器或网络 连接速度比较快 ping 还能显示 TTL TimeToLive 生存时间 值 通过 TTL 值可以推算数据包通过了多

    2026年3月17日
    2
  • linux进程管理工具:supervisor

    linux进程管理工具:supervisor1 安装 yuminstallsu 或者 apt getinstallsu 配置 supervisor 有两类配置文件 2 1 主配置文件默认路径 etc supervisord conf 这个目录一般不用动 需要管理进程的话 给进程单独创建一个配置文件就好 2 2 进程单独配置文件默认路径 etc supervisord d ini 默认是 ini 后缀 可以在主配置文件中修改 每个进程的管

    2026年3月17日
    2
  • 传奇——用回忆感受幸福,用记忆寻找快乐

    传奇——用回忆感受幸福,用记忆寻找快乐

    2021年7月27日
    62

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号