在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. HDU 1176 免费馅饼【动态规划】

    解题思路:用a[i][j]表示在第i秒在地点j的掉落馅饼的数量,设整个馅饼掉落的时间持续为timemax,即为矩阵的高度,一共0到10个地点,为矩阵的长度,如图,即可构成数塔,因为考虑到在地点0的时候 ...

  2. 脚本_使用expect自动交互远程主机安装软件

    #!bin/bash#功能:使用expect工具自动交互密码,远程到其它主机,安装httpd软件#作者:liusingbon#删除~/.ssh/known-hosts后,ssh远程任何主机,系统都会询 ...

  3. [置顶] openHAB 体系结构与编程模型 (2) --- Web Application Servlet 源码结构

    || || || || || || demo.items Group All Group gGF (All) Group gFF (All) Group gC (All) Group Outdoor ...

  4. IDEA使用操作说明(自己总结)

    1.idea导入一个项目后,如何再导入另一个项目 首先,点击File-->new-->Module from Existing Sources...-->找到该项目所在位置,选中该项 ...

  5. 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] D】Single-use Stones

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 设长度为L的所有区间里面,石头的个数的最小值为k 设取到k的区间为l,r 那么k就为最多能通过的青蛙个数. 假设k再大一点.比如为k ...

  6. [POJ3233]Matrix Power Series 分治+矩阵

    本文为博主原创文章,欢迎转载,请注明出处 www.cnblogs.com/yangyaojia [POJ3233]Matrix Power Series 分治+矩阵 题目大意 A为n×n(n<= ...

  7. ubuntu下使用Nexus搭建Maven私服

    ubuntu下使用Nexus搭建Maven私服 1.私服简介: 私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件.有了私服之后,当 Maven 需要下载构件时,直接请求私服, ...

  8. [Ubuntu]安装中文输入法

    安装了英文版的Ubuntu12.04之后.使用ctrt+space无法切换到中文,才反应过来. 于是查询了下怎么在Ubuntu下安装和配置中文输入法. 第一步安装语言包: 在左側的菜单条中点击 sys ...

  9. FZU_Problem 2168 防守阵地 I

    Problem 2168 防守阵地 I Accept: 128 Submit: 392 Time Limit: 3000 mSec Memory Limit : 32768 KB Problem De ...

  10. EF的CRUD

    已经知道EF就是一个能够使得编程人员用面向对象的思想操作数据库的框架,那么在最初学习SQL的时候我们就知道对数据库的操作就是增删改查.万变不离其宗. EF也是操作数据库的当然也就是要对数据库实现增删改 ...