在JAVA中注解@SuppressWarnings("deprecation")的Deprecation是什么意思

过期的
@SuppressWarnings("deprecation")表示不检测过期的方法

一、前言                                  


编码时我们总会发现如下变量未被使用的警告提示:



上述代码编译通过且可以运行,但每行前面的“感叹号”就严重阻碍了我们判断该行是否设置的断点了。这时我们可以在方法前添加 @SuppressWarnings("unused") 去除这些“感叹号”。



二、 @SuppressWarings注解                            


  作用:用于抑制编译器产生警告信息。


示例1——抑制单类型的警告:


@SuppressWarnings("unchecked")
public void addItems(String item){
@SuppressWarnings("rawtypes")
List items = new ArrayList();
items.add(item);
}

示例2——抑制多类型的警告:


@SuppressWarnings(value={"unchecked", "rawtypes"})
public void addItems(String item){
List items = new ArrayList();
items.add(item);
}

示例3——抑制所有类型的警告:


@SuppressWarnings("all")
public void addItems(String item){
List items = new ArrayList();
items.add(item);
}


三、注解目标                                


通过 @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
finally  to suppress warnings relative to finally block that don’t return
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)
nls  to suppress warnings relative to non-nls string literals
null to suppress warnings relative to null analysis
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
static-access o 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

 

注解@SuppressWarnings的更多相关文章

  1. 知识点:java 注解 @SuppressWarnings

    前言: 简介:java.lang.SuppressWarnings是J2SE5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上.作用:告诉编译器忽略指定的 ...

  2. java注解 @SuppressWarnings注解用法

    @SuppressWarnings注解用法 @SuppressWarnings注解主要用在取消一些编译器产生的警告对代码工具左侧行列提示,但这种警告可以通过注释类型声明来取消 @SuppressWar ...

  3. 忽略警告注解@SuppressWarnings详解

    简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上. 作用:告诉编译器忽略指定的警告 ...

  4. Spring的注解@SuppressWarnings用法记录

    @SuppressWarnings注解用法 @SuppressWarnings注解主要用在取消一些编译器产生的警告对代码左侧行列的遮挡,有时候这会挡住我们断点调试时打的断点. 如图所示: 这时候我们在 ...

  5. sping中 各种注解——@SuppressWarnings注解用法

    @SuppressWarnings注解用法 @SuppressWarnings注解主要用在取消一些编译器产生的警告对代码左侧行列的遮挡,有时候这会挡住我们断点调试时打的断点. 如图所示: 这时候我们在 ...

  6. java retention注解

    Retention注解 Retention(保留)注解说明,这种类型的注解会被保留到那个阶段. 有三个值:1.RetentionPolicy.SOURCE —— 这种类型的Annotations只在源 ...

  7. 黑马程序员:Java基础总结----java注解

    黑马程序员:Java基础总结 java注解   ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! java注解 lang包中的基本注解 @SuppressWarnings ...

  8. 10分钟学会JAVA注解(annotation)

    (原) 先认识注解(Annotation) 定义类用class,定义接口用interface,定义注解用@interface 如public @interface AnnotationTest{} 所 ...

  9. java注解--Annotation

    Annotation(注释) 概述 从 JDK 5.0 开始, Java 增加了对元数据(MetaData) 的支持, 也就是 Annotation(注释) Annotation 其实就是代码里的特殊 ...

随机推荐

  1. Pyhton学习——Day34

    # 任何语言都会发生多线程,会出现不同步的问题,同步锁.死锁.递归锁# 异步: 多任务, 多个任务之间执行没有先后顺序,可以同时运行,执行的先后顺序不会有什么影响,存在的多条运行主线# 同步: 多任务 ...

  2. MySQL 关闭 binlog 日志

    [关闭binlog日志] 1.vim /etc/my.cnf 注释如下内容: #log-bin=mysql-bin #binlog_format=mixed #server-id = 1 #expir ...

  3. 【HiJ1m】在NOIP2017前写过的有用的东西汇总

    http://www.cnblogs.com/Elfish/p/7544623.html 高级树状数组 http://www.cnblogs.com/Elfish/p/7554420.html BST ...

  4. CF343E Pumping Stations(最小割树)

    没学过最小割树的出门左转. 我们已经知道了两点的最小割就是最小割树上,对应两点之间路径的权值的最小值. 找到最小割树中权值的最小的边. 那么一定是先选完一侧的点在选完另一侧的点. 因为当前边最小,那么 ...

  5. [COCI2007]PRAVOKUTNI

    题目大意:在一个平面上,有\(N\)个点,求这些点构成的直角三角形个数.解题思路:枚举直角顶点,对于每个点,将这个点当做原点,对其他点按极角排序,然后双指针扫一遍,判断弧度差即可. C++ Code: ...

  6. Linux版本分支图

  7. 命令行导入导出Mysql数据库

    MySQL命令行导出数据库:1,进入MySQL目录下的bin文件夹:cd MySQL中到bin文件夹的目录,如我输入的命令行:cd C:\Program Files\MySQL\MySQL Serve ...

  8. 洛谷P5238 整数校验器

    看到没有边读入边处理的,我来水一发 我们要看一下有那些情况是格式不合法的 单独的负号 -0(后面可以有其他数字) 0 +(后面一些数字) 我们用快速读入的方法 读取字符进行处理 还有可能超出范围的 考 ...

  9. [luogu] P4105 [HEOI2014]南园满地堆轻絮 (贪心)

    P4105 [HEOI2014]南园满地堆轻絮 题目描述 小 Z 是 ZRP(Zombies' Republic of Poetry,僵尸诗歌共和国)的一名诗歌爱好者,最近 他研究起了诗词音律的问题. ...

  10. hbase的hbase-site.xml配置文件

    <property> <name>hbase.rootdir</name> <value>hdfs://server110/hbase</valu ...