@SupperessWarnings

一.简介:java.lang.SupperessWarnings是J2SE5.0标准的Annotation之一。可以标注在类,字段,方法,参数,构造方法,局部变量上。

二.作用:该注解的作用是给编译器一条指令,告诉它对批注的代码元素内部的某些警告保持静默,不在编译完成后出现警告信息。

三.使用

@SuppressWarnings(“”)
@SuppressWarnings({})
@SuppressWarnings(value={})

示例:

·  @SuppressWarnings("unchecked")
告诉编译器忽略 unchecked 警告信息,如使用List,ArrayList等未进行参数化产生的警告信息。
·  @SuppressWarnings("serial")
如果编译器出现这样的警告信息:The serializable class WmailCalendar does notdeclare a static final serialVersionUID field of type long
      使用这个注释将警告信息去掉。
·  @SuppressWarnings("deprecation")
如果使用了使用@Deprecated注释的方法,编译器将出现警告信息。
      使用这个注释将警告信息去掉。
·  @SuppressWarnings("unchecked", "deprecation")
告诉编译器同时忽略unchecked和deprecation的警告信息。
·  @SuppressWarnings(value={"unchecked", "deprecation"})

等同于@SuppressWarnings("unchecked", "deprecation")

编码时候出现如下的警告提示:

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

四.注解里面使用的关键字

  • 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(使用generics时忽略没有指定相应的类型)
  • 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(忽略在serializable类中没有声明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  (抑制没被使用过的代码的警告)

@SuppressWarnings注解详解相关推荐

  1. Java基础13:反射与注解详解

    Java基础13:反射与注解详解 什么是反射? 反射(Reflection)是Java 程序开发语言的特征之一,它允许运行中的 Java 程序获取自身的信息,并且可以操作类或对象的内部属性. Orac ...

  2. 26.SpringBoot事务注解详解

    转自:https://www.cnblogs.com/kesimin/p/9546225.html @Transactional spring 事务注解 1.简单开启事务管理 @EnableTrans ...

  3. mybatis注解详解

    mybatis注解详解 首 先当然得下载mybatis-3.0.5.jar和mybatis-spring-1.0.1.jar两个JAR包,并放在WEB-INF的lib目录下 (如果你使用maven,则 ...

  4. 开启注解缓存_Spring Boot 2.x基础教程:进程内缓存的使用与Cache注解详解

    随着时间的积累,应用的使用用户不断增加,数据规模也越来越大,往往数据库查询操作会成为影响用户使用体验的瓶颈,此时使用缓存往往是解决这一问题非常好的手段之一.Spring 3开始提供了强大的基于注解的缓 ...

  5. spring-boot注解详解(一)

    spring-boot注解详解(一) @SpringBootApplication @SpringBootApplication = (默认属性)@Configuration + @EnableAut ...

  6. Spring零配置之@Configuration注解详解

    转载自 Spring零配置之@Configuration注解详解 @Configuration介绍 Spring3.0之前要使用Spring必须要有一个xml配置文件,这也是Spring的核心文件,而 ...

  7. Spring Boot注解详解

    文章目录 使用注解的优势 注解详解(配备了完善的释义) 注解列表如下 JPA注解 springMVC相关注解 全局异常处理 项目中具体配置解析和使用环境 使用注解的优势 采用纯java代码,不在需要配 ...

  8. 【SpringBoot 】SpringBoot注解详解

    [SpringBoot ]SpringBoot注解详解 一.注解(annotations)列表  @SpringBootApplication:包含了@ComponentScan.@Configura ...

  9. java method 注解_JAVA 注解详解及简单实例

    JAVA 注解详解及简单实例 何为注解 注解(Annotation)又称为元数据,在JDK1.5后引入,它的作用是: 生成文档  这是注解的原始用途,可以通过注解生成JavaDoc文档 跟踪代码的依赖 ...

最新文章

  1. python 使用import导入不同文件下的文件
  2. 据说这是大多数人【减肥】的真实写照
  3. 详解GCN、GAT、凸优化、贝叶斯、MCMC、LDA
  4. insert获取主键、联合关联查询
  5. Prolog 语言入门
  6. validate验证长度 vue_vue input 输入校验字母数字组合且长度小于30的实现代码
  7. 你还在为20倍的连麦成本发愁吗?
  8. 自己实现JSON、XML的解析 没那么难
  9. Taro+react开发(5)--tora项目开发安装
  10. iOS逆向工程(简单利用dumpdecrypted给ipa砸壳)
  11. CompletableFuture 异步编程
  12. 树状数组--快捷的线段树
  13. TCP的电话系统比喻
  14. wpf 自动完成comboxBox
  15. iphone 控制 android手机,新潮来袭:苹果手机控制安卓手机
  16. nginx源码编译安装和配置
  17. Re: 一个公司如何才能留住员工呢?
  18. CryEngine事件监听器概览
  19. 解决win2003里IIS运行ASP时出现请求资源在使用中的问题
  20. 年轻人转行需三思,未来5-10年什么工作真吃香?

热门文章

  1. SX126x-工作模式分析
  2. 洛克菲勒给儿子的38封信(前14封选摘)
  3. 目标检测领域论文和代码集合(2013年~2018年8月)
  4. 18.字符串练习---判断是否是回文数
  5. Tomcat启动出错详解
  6. 搬家货运系统软件开发功能
  7. 经典面试题:翻转英文句子中单词的顺序
  8. NSX-T系列:第1部分 - 架构和部署
  9. usb udc 驱动
  10. 服务器推送/客服端拉扯