@SuppressWarnings https://www.cnblogs.com/fsjohnhuang/p/4040785.html
一、前言
编码时我们总会发现如下变量未被使用的警告提示:

上述代码编译通过且可以运行,但每行前面的“感叹号”就严重阻碍了我们判断该行是否设置的断点了。这时我们可以在方法前添加 @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 |
五、Java Lint选项
1. lint的含义
用于在编译程序的过程中,进行更细节的额外检查。
2. javac 的标准选项和非标准选项
标准选项:是指当前版本和未来版本中都支持的选项,如 -cp 和 -d 等。
非标准选项:是指当前版本支持,但未来不一定支持的选项。通过 javac -X 查看当前版本支持的非标准选项。

3. 查看警告信息
默认情况下执行 javac 仅仅显示警告的扼要信息,也不过阻止编译过程。若想查看警告的详细信息,则需要执行 javac -Xlint:keyword 来编译源码了。
六、总结
现在再都不怕不知道设置断点没有咯!
尊重原创,转载请注明来自:http://www.cnblogs.com/fsjohnhuang/p/4040785.html ^_^肥仔John
七、参考
http://blog.csdn.net/mddy2001/article/details/8291484
http://www.cnblogs.com/liubiqu/archive/2008/06/01/1211503.html
http://www.360doc.com/content/13/0913/17/1171_314224417.shtml
@SuppressWarnings https://www.cnblogs.com/fsjohnhuang/p/4040785.html的更多相关文章
- 访问路径:https://i.cnblogs.com/posts?categoryid=925678
https://i.cnblogs.com/posts?categoryid=925678
- URL https://i.cnblogs.com/EditPosts.aspx?opt=1
URL url = new URL("https://i.cnblogs.com");URL url1 = new URL(url, "EditPosts.aspx?op ...
- 随笔二-https://www.cnblogs.com/shang1680/p/9657994.html
作业要求来自https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2097 GitHub远程仓库的地址:https://github.com/ ...
- 211806189杨昊辰 https://www.cnblogs.com/honey1433223/
211806189杨昊辰 https://www.cnblogs.com/honey1433223/
- https://www.cnblogs.com/h2zZhou/p/5440271.html
https://www.cnblogs.com/h2zZhou/p/5440271.html
- https://www.cnblogs.com/soundcode/p/4174410.html
https://www.cnblogs.com/soundcode/p/4174410.html 1.首先要在服务器端新建一个网站axpx页 然后再网站的后台写代码获取winform传过来的文件名. ...
- https://www.cnblogs.com/yudanqu/p/9467803.html
https://www.cnblogs.com/yudanqu/p/9467803.html
- 转发自:一像素 十大经典排序算法(动图演示)原链接:https://www.cnblogs.com/onepixel/articles/7674659.html 个人收藏所用 侵删
原链接:https://www.cnblogs.com/onepixel/articles/7674659.html 个人收藏所用 侵删 0.算法概述 0.1 算法分类 十种常见排序算法可 ...
- @无痕客 https://www.cnblogs.com/wuhenke/archive/2012/12/24/2830530.html 通篇引用
无痕客 https://www.cnblogs.com/wuhenke/archive/2012/12/24/2830530.html 关于Async与Await的FAQ 关于Async与Await的 ...
随机推荐
- css发展过程
https://www.cnblogs.com/dashnowords/p/9460722.html
- c# wpf 加密文本
可以加密人们的内容,文本加密. 界面 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation& ...
- redux中间件来执行异步操作
在redux中我们都是执行同步操作,如果我们想要执行异步操作,那么我们就需要依赖到中间件,具体的中间件的概念我就不描述了相信官方文档更详尽.现在就描述下具体的用法,就已我们项目中用到的最多的数据请求为 ...
- ubuntu安装软件失败
Unable to fetch some archives, maybe run apt-get update or try with --fix-missing sudo gedit /etc/ho ...
- CSP-S 赛前模板复习
快读模板 这个连算法都算不上... inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9') ...
- sql中的group_concat用法
group_concat(),手册上说明:该函数返回带有来自一个组的连接的非NULL值的字符串结果.比较抽象,难以理解. 通俗点理解,其实是这样的:group_concat()会计算哪些行属于同一组, ...
- 在Wi-Fi路由器中发现了新的安全漏洞
黑客利用两种互联网通用协议的互动的漏洞:传输控制协议,或TCP和Wi-Fi.该漏洞利用并不针对任何传统的安全漏洞.相反,安全方面的弱点在于20多年前制定的基本Wi-Fi设计决策极难改变. 中国黑客教父 ...
- kettle中使用mysql的tinyint 类型到slqserver的tinyint类型
各个数据库之间的类型 定义还是有差别的 一下是我在工作中遇到的一个很奇葩的问题 mysql 中的 tinyint 类型 插入到sqlserver 的tinyint 类型 插入到 sqlserver的 ...
- 【leetcode】1103. Distribute Candies to People
题目如下: We distribute some number of candies, to a row of n = num_people people in the following way: ...
- SpringMVC最新教程IDEA版
1.servlet项目结构与识别 Idea里带个蓝点的文件夹为tomcat吃的网站内容,idea会通过“Web Resource Directory”来标注,会被打成一个war包 这个文件夹里,MET ...