一、前言                                  

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

上述代码编译通过且可以运行,但每行前面的“感叹号”就严重阻碍了我们判断该行是否设置的断点了。这时我们可以在方法前添加 @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的更多相关文章

  1. 访问路径:https://i.cnblogs.com/posts?categoryid=925678

    https://i.cnblogs.com/posts?categoryid=925678

  2. 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 ...

  3. 随笔二-https://www.cnblogs.com/shang1680/p/9657994.html

    作业要求来自https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2097 GitHub远程仓库的地址:https://github.com/ ...

  4. 211806189杨昊辰 https://www.cnblogs.com/honey1433223/

    211806189杨昊辰 https://www.cnblogs.com/honey1433223/

  5. https://www.cnblogs.com/h2zZhou/p/5440271.html

    https://www.cnblogs.com/h2zZhou/p/5440271.html

  6. https://www.cnblogs.com/soundcode/p/4174410.html

    https://www.cnblogs.com/soundcode/p/4174410.html 1.首先要在服务器端新建一个网站axpx页 然后再网站的后台写代码获取winform传过来的文件名. ...

  7. https://www.cnblogs.com/yudanqu/p/9467803.html

    https://www.cnblogs.com/yudanqu/p/9467803.html

  8. 转发自:一像素 十大经典排序算法(动图演示)原链接:https://www.cnblogs.com/onepixel/articles/7674659.html 个人收藏所用 侵删

    原链接:https://www.cnblogs.com/onepixel/articles/7674659.html     个人收藏所用   侵删 0.算法概述 0.1 算法分类 十种常见排序算法可 ...

  9. @无痕客 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的 ...

随机推荐

  1. vscode 热部署 spring-mvc

    1.添加maven插件 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId> ...

  2. [转]0day零距离

    前言: 想起这个话题,还要从早年网上的一则新闻说起--"美国联邦官员于2001年12月11日宣布,已破获一起以因特网为犯罪手段的特大软件盗版案--盗版软件的总价值至少高达10亿美元.据悉,该 ...

  3. Python中numpy的应用

    #创建ndarray import numpy as np nd = np.array([2,4,6,'])#numpy中默认ndarray的所有元素的数据类型是相同,如果数据的类型不同,会统一为统一 ...

  4. 4--面试总结-promise

    promise异步原理: 定义:promise是异步编程的解决方案,可以解决异步回调地狱的问题: 原理:三种状态两种结果的一个状态机:三种状态(pending,fulfilled,rejected)两 ...

  5. bzoj4883 [Lydsy1705月赛]棋盘上的守卫 最小生成基环树森林

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4883 题解 每一行和每一列都必须要被覆盖. 考虑对于每一行和每一列都建立一个点,一行和一列之间 ...

  6. postman—UI测试

    思路 发送请求去拿到网站的响应->html 解析HTML标签,判断一些元素是否显示 目的 快速检查UI是否正确 测试地址 http://www.itest.info/courses 我们接下来要 ...

  7. 6411. 【NOIP2019模拟11.06】上网

    题目描述 Description Input Output 若无解,则输出"Impossible". 否则第一行输出"Possible",第二行输出 n 个正整 ...

  8. Bugku 杂项 眼见非实(ISCCCTF)

    眼见非实(ISCCCTF) 下载文件后,用winhex打开 发现文件头为50 4B 03 04说明是一个压缩文件,还可以看到其中有.docx文件 更改文件后缀为 .zip 解压后发现 这个文件用wor ...

  9. luogu 4147 玉蟾宫 悬线DP

    Code: #include<bits/stdc++.h> using namespace std; #define setIO(s) freopen(s".in",& ...

  10. KNN算法之KD树

    KD树算法是先对数据集进行建模,然后搜索最近邻,最后一步是预测. KD树中的K指的是样本特征的维数. 一.KD树的建立 m个样本n维特征,计算n个特征的方差,取方差最大的第k维特征作为根节点.选择第k ...