java注解 @SuppressWarnings注解用法
@SuppressWarnings注解用法
@SuppressWarnings注解主要用在取消一些编译器产生的警告对代码工具左侧行列提示,但这种警告可以通过注释类型声明来取消
@SuppressWarnings常用的注解的使用有三种:
1. @SuppressWarnings("unchecked") [抑制没有进行类型检查操作的警告]
2. @SuppressWarnings("unchecked","rawtypes") [抑制多类型的警告]
3. @SuppressWarnings("unused") [抑制没被使用过的代码的警告]
通过源码分析可知@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( 使用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( 抑制没被使用过的代码的警告) |
java注解 @SuppressWarnings注解用法的更多相关文章
- Java中@SuppressWarnings注解用法(转)
背景: J2SE提供的最后一个注解是@SuppressWarnings.该批注的作用是给编译器一条指令,告诉它对被批注的代码元素内部的某些警告保持静默. @SuppressWarnings注解允许您选 ...
- JAVA中@SuppressWarnings注解的作用
eclipse中开发JAVA代码时,经常会出现编译告警符号,影响代码可读性,也影响调试的断点符号正常显示,可以使用@SuppressWarnings注解来抑制这些告警符号的再现.1.抑制单个类型的告警 ...
- sping中 各种注解——@SuppressWarnings注解用法
@SuppressWarnings注解用法 @SuppressWarnings注解主要用在取消一些编译器产生的警告对代码左侧行列的遮挡,有时候这会挡住我们断点调试时打的断点. 如图所示: 这时候我们在 ...
- 知识点:java 注解 @SuppressWarnings
前言: 简介:java.lang.SuppressWarnings是J2SE5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上.作用:告诉编译器忽略指定的 ...
- @SuppressWarnings注解用法详解
@SuppressWarnings注解用法详解 今天来谈谈@SuppressWarnings注解的作用. J2SE 提供的最后一个批注是 @SuppressWarnings.该批注的作用是给编译器一条 ...
- Java注解Annotation的用法 - 自定义Annotation实现
Java注解又称Java标注,是Java语言5.0版本开始支持加入源代码的特殊语法元数据. Java语言中的类.方法.变量.参数和包等都可以被标注.和Javadoc不同,Java标注可以通过反射获取标 ...
- Spring的注解@SuppressWarnings用法记录
@SuppressWarnings注解用法 @SuppressWarnings注解主要用在取消一些编译器产生的警告对代码左侧行列的遮挡,有时候这会挡住我们断点调试时打的断点. 如图所示: 这时候我们在 ...
- @SuppressWarnings注解用法
@SuppressWarnings注解主要用在取消一些编译器产生的警告对代码左侧行列的遮挡,有时候这会挡住我们断点调试时打的断点. 如图所示: 这时候我们在方法上加上@SuppressWarnings ...
- @SuppressWarnings注解用法详解(转)
原文连接https://blog.csdn.net/sysware_carol/article/details/52100580 今天来谈谈@SuppressWarnings注解的作用. J2SE 提 ...
随机推荐
- jenkins+maven+svn+npm自动发布部署实践
一.系统版本centos7.6 二.根据jenkins官方安装方法yum安装jenkins 1.进入jenkins官网下载页面https://jenkins.io/download/,选择Red Ha ...
- LintCode——合并排序数组II
描述:合并两个排序的整数数组A和B变成一个新的数组 样例:给出A=[1,2,3,4],B=[2,4,5,6],返回 [1,2,2,3,4,4,5,6] 1.Python:先将数组B加到数组A之后,然后 ...
- springmvc 集成apache cxf 开发webservice 示例
今天需要在springmvc中增加webservice功能,试了多次axis2,和cxf都不行,后来发现在springmvc中最好用cxf集成非常方便,在又一次尝试后终于把demo整合到现有的项目中 ...
- linux内核分析第三次实验
http://blog.sina.com.cn/s/blog_78e559950102wo67.html
- LeetCode 88. 合并两个有序数组
题目: 给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 说明: 初始化 nums1 和 nums2 的元素数量分别为 m ...
- Beta冲刺——day2
Beta冲刺--day2 作业链接 Beta冲刺随笔集 github地址 团队成员 031602636 许舒玲(队长) 031602237 吴杰婷 031602220 雷博浩 031602134 王龙 ...
- Docker(九)-Docker创建Selenium容器
SeleniumHQ官方项目:https://github.com/seleniumHQ/docker-selenium 项目目前快速迭代中. Selenium 这里主要针对的是 Selenium G ...
- 还在手动给css加前缀?no!几种自动处理css前缀的方法简介
原文首发于个人博客:还在手动给css加前缀?no!几种自动处理css前缀的方法简介 我们知道在写css的时候由于要兼容不同厂商浏览器,一些比较新的属性需要给它们添加厂商前缀来兼容.移动端还好,基本只要 ...
- idea中 读取mybatis的配置文件时候 如果放在文件下面 需要加上路径
- 题解 P1184 【高手之在一起】
好!机会来了! 依评论区的要求,小金羊献上STLset<string>的题解. 当然不会告诉你map<string,bool>我根本不会用 所以,有什么内置的成员函数救救孩子? ...