@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,开发人员可 ...
随机推荐
- NYOJ 163 Phone List (字符串处理 字典树)
题目链接 描述 Given a list of phone numbers, determine if it is consistent in the sense that no number is ...
- 回溯算法_01背包问题_Java实现
原文地址:http://blog.csdn.net/ljmingcom304/article/details/50314839 本文出自:[梁敬明的博客] 1.回溯算法 回溯算法也叫试探法,通俗的将就 ...
- C# 加密解密以及sha256不可逆加密案例
class Program { static void Main(string[] args) { string aa = "身份证"; string bb = "key ...
- Android Studio 找不到EventBus/ButterKnife等第三方包解决方案
废话不多说,有图有真相 Q·:可以正常Build,debug就是看着不舒服,代码提示也出不来. 解决方案: 1. invalidate and restart (没用继续第二步) 2. 修改gradl ...
- Tutorial 4: Authentication & Permissions
转载自:http://www.django-rest-framework.org/tutorial/4-authentication-and-permissions/ Tutorial 4: Auth ...
- Idea安装Scala插件(转)
原文链接:http://blog.csdn.net/a2011480169/article/details/52712421 参考博客: 1.http://wwwlouxuemingcom.blog. ...
- 详解Oracle的unlimited tablespace系统权限
1. 系统权限unlimited tablespace是隐含在dba, resource角色中的一个系统权限. 当用户得到dba或resource的角色时, unlimited tablespace系 ...
- 百度NLP面试题
C++ : 1.拷贝构造函数和重载=符分别在什么情况下被调用,实现有什么区别 2.虚函数的目的,虚函数和模板类的区别,如何找到虚函数 常规算法: 1. 如何输出一个集合的所有真子集,递归和非递 ...
- [VBA]批量替换PPT里的字体颜色
不知道为什么计组老师的大量课件字体是伤害视力的亮蓝色……看久了眼睛疼,想把颜色替换成保护视力一点的灰色,但是找了N久也没找到在图形界面上直接操作的方法,于是在MSDN上晃了晃,Google了一下,写了 ...
- SQL Join简单介绍
前沿 Join是关系型数据库系统的重要操作之一,SQL Server中包含的常用Join:内联接.外联接和交叉联接等. 如果我们想在两个或以上的表获取其中从一个表中的行与另一个表中的行匹配的数据,这时 ...