@SuppressWarning 抑制警告注解
@SuppressWarning 抑制警告注解
Java.lang.SuppressWarnings 是 J2SE5.0中标准的Annotation 之一。
可以标注在类,字段,方法,参数,构造方法,以及局部变量上。
作用
告诉编辑器忽略指定的警告,不用再编译完成后出现警告信息。
使用
@ SuppressWarnings(“ ”)
@ SuppressWarnings({ })
@ SuppressWarnings(value={})
注意:
@SuppressWarnings(value={"unchecked", "deprecation"}) 等同于@SuppressWarnings("unchecked", "deprecation")
若需要多个抑制警告类型,我们可以使用逗号隔开 @ SuppressWarnings(value={“unchecked” , “boxing”})
示例:编码时我们会发现,若变量未被引用时,会出现黄色警告
上面的代码编译通过且可以正常运行,但是每行前面的黄色警告严重阻碍我们判断该行是否设置了断点。
此时我们可以使用 @ SuppressWarnings(“ ”) 注解,来去除这些警告信息
示例:
此时,我们会发现黄色警告已经没有了,这时就不妨碍我们进行判断是否设置了断点。
抑制警告关键字
all |
to suppress all warnings 抑制所有警告 |
boxing |
to suppress warnings relative to boxing/unboxing operations 抑制装箱,拆箱操作时候的警告 |
cast |
to suppress warnings relative to cast operations 抑制映射相关的警告 |
dep-ann |
to suppress warnings relative to deprecated annotation 抑制启用注释的警告 |
deprecation |
to suppress warnings relative to deprecation 抑制过期方法警告 |
fallthrough |
to suppress warnings relative to missing breaks in switch statements 抑制确定switch中缺失breaks的警告 |
finally |
to suppress warnings relative to finally block that don’t return 抑制finally模块没有返回的警告 |
hiding |
to suppress warnings relative to locals that hide variable |
incomplete-switch |
to suppress warnings relative to missing entries in a switch statement (enum case) 忽略没有完整的switch语句 |
nls |
to suppress warnings relative to non-nls string literals 忽略非nls 格式的字符 |
null |
to suppress warnings relative to null analysis 忽略对null的操作 |
rawtypes |
to suppress warnings relative to un-specific types when using generics on class params 使用泛型类型时忽略没有指定相应的类型 |
restriction |
to suppress warnings relative to usage of discouraged or forbidden references |
serial |
to suppress warnings relative to missing serialVersionUID field for a serializable class 忽略在序列化类中没有声明serialVersionUID变量 |
static-access |
to suppress warnings relative to incorrect static access 抑制不正确的静态访问方式警告 |
synthetic-access |
to suppress warnings relative to unoptimized access from inner classes 抑制子类没有按最优方法访问内部类的警告 |
unchecked |
to suppress warnings relative to unchecked operations 抑制没有进行类型检查操作的警告 |
unqualified-field-access |
to suppress warnings relative to field access unqualified 抑制没有权限访问的域的警告 |
unused |
to suppress warnings relative to unused code 抑制没被使用过的代码的警告 |
@SuppressWarning 抑制警告注解的更多相关文章
- 忽略警告注解@SuppressWarnings详解
简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上. 作用:告诉编译器忽略指定的警告 ...
- simplexml_load_file 抑制警告的直接输出
$xml = simlexml_load_file($file, null, LIBXML_NOERROR); if (!is_object($this->xml)){ throw new Ex ...
- @SuppressWarnings抑制警告
@SuppressWarnings(“XXXX”) 来抑制编译时的警告信息.参数如下: 关键字 用途 all to suppress all warnings boxing to suppress ...
- Java中@Deprecated、@SupressWarning、@Override的作用
Annotation注解在 Java 中有着很广泛的,他是做为一种标识 为javac所识别.每一个注解 都对应这一个Java类 在java.lang包中 有三个注解 分别是 Deprecated ...
- JavaEE进阶集锦(持续更新中)
1.影响Servlet生命周期的注解:@PostConstruct和@PreDestroy @PostConstruct:被修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器调用一次, ...
- 去除编译警告@SuppressWarnings注解用法详解(转)
使用:@SuppressWarnings(“”)@SuppressWarnings({})@SuppressWarnings(value={}) 编码时我们总会发现如下变量未被使用的警告提示: 上述代 ...
- Java @SuppressWarnings:抑制编译器警告-4
Java 中的 @SuppressWarnings 注解指示被该注解修饰的程序元素(以及该程序元素中的所有子元素)取消显示指定的编译器警告,且会一直作用于该程序元素的所有子元素.例如,使用 @Supp ...
- Java注解
Java注解其实是代码里的特殊标记,使用其他工具可以对其进行处理.注解是一种元数据,起到了描述.配置的作用,生成文档,所有的注解都隐式地扩展自java.lang.annotation.Annotati ...
- Java注解Annotation详解
从JDK5开始,Java增加了Annotation(注解),Annotation是代码里的特殊标记,这些标记可以在编译.类加载.运行时被读取,并执行相应的处理.通过使用Annotation,开发人员可 ...
随机推荐
- Sublime快捷键(一)
最近在工作中,遇到的sublime的快捷键,以后再工作中用到的我会稍后增加的~ 快捷键: 1.切换标签页: Ctrl + Tab 切换标签页: Ctrl + Shift + Tab 返回刚切 ...
- 树的直径(两个bfs)
题目链接:https://cn.vjudge.net/problem/POJ-2631 树的直径:树中的最长链 具体思路:随便找一个点bfs,然后找到最长的链,然后再以找到的点作为起点进行bfs,然后 ...
- CentOS 6.5 安装 MongoDB
1. 配置 yum 新建 /etc/yum.repos.d/mongodb-org-3.4.repo 文件,使用以下配置:(适用于 MongoDB 3.0 以后版本) [mongodb-org-3.4 ...
- linux ip白名单、防火墙白名单 设置
http://blog.csdn.net/catoop/article/details/50476099 登录信息在 /var/log/secure linux ip白名单 配置文件:/etc/hos ...
- 一个TCP报文段的数据部分最多为多少个字节,为什么
IP数据报的最大长度=2^16-1=65535(字节)TCP报文段的数据部分=IP数据报的最大长度-IP数据报的首部-TCP报文段的首部=65535-20-20=65495(字节) 一个tcp报文段的 ...
- linux下的僵尸进程处理SIGCHLD信号【转】
转自:http://www.cnblogs.com/wuchanming/p/4020463.html 什么是僵尸进程? 首先内核会释放终止进程(调用了exit系统调用)所使用的所有存储区,关闭所有打 ...
- shell source命令说明
当我修改了/etc/profile文件,我想让它立刻生效,而不用重新登录:这时就想到用source命令,如:source /etc/profile对source进行了学习,并且用它与sh 执行脚本进行 ...
- Workqueue机制的实现
Workqueue机制中定义了两个重要的数据结构,分析如下: cpu_workqueue_struct结构.该结构将CPU和内核线程进行了绑定.在创建workqueue的过程中,Linux根据当前系统 ...
- Centos查看端口占用和关闭端口
Centos查看端口占用情况命令,比如查看80端口占用情况使用如下命令: lsof -i tcp:80 列出所有端口 netstat -ntlp 1.开启端口(以80端口为例) ...
- laravel 上传文件到亚马逊 aws s3
参考: https://github.com/aws/aws-sdk-php-laravel https://www.jianshu.com/p/e48d82bff20b