2019独角兽企业重金招聘Python工程师标准>>>

一、前言                                  

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

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

转载于:https://my.oschina.net/u/2442830/blog/709753

@SuppressWarnings注解的详解相关推荐

  1. @SuppressWarnings注解用法详解

    @SuppressWarnings注解是jse提供的注解.作用是屏蔽一些无关紧要的警告.使开发者能看到一些他们真正关心的警告.从而提高开发者的效率 简介:java.lang.SuppressWarni ...

  2. 去除编译警告@SuppressWarnings注解用法详解(转)

    使用: @SuppressWarnings("") @SuppressWarnings({}) @SuppressWarnings(value={}) 编码时我们总会发现如下变量未 ...

  3. Java 注解用法详解——@SuppressWarnings

    转自: https://www.cnblogs.com/fsjohnhuang/p/4040785.html Java魔法堂:注解用法详解--@SuppressWarnings 一.前言 编码时我们总 ...

  4. spring之旅第四篇-注解配置详解

    spring之旅第四篇-注解配置详解 一.引言 最近因为找工作,导致很长时间没有更新,找工作的时候你会明白浪费的时间后面都是要还的,现在的每一点努力,将来也会给你回报的,但行好事,莫问前程!努力总不会 ...

  5. Java注解(Annotation)详解

    转: Java注解(Annotation)详解 幻海流心 2018.05.23 15:20 字数 1775 阅读 380评论 0喜欢 1 Java注解(Annotation)详解 1.Annotati ...

  6. Spring 3.0 注解注入详解

    Spring 3.0 注解注入详解 2011-04-15 09:44 17ZOUGUO ITEYE博客 我要评论(1) 字号:T | T AD: 一.各种注解方式 1.@Autowired注解(不推荐 ...

  7. spring MVC请求处理类注解属性详解

    spring MVC请求处理类注解属性详解

  8. Retrofit 注解参数详解

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/121000230 本文出自[赵彦军的博客] 系列文章推荐: Android Flow ...

  9. JAVA元注解@interface详解(@Target,@Documented,@Retention,@Inherited)

    转载自 JAVA元注解@interface详解(@Target,@Documented,@Retention,@Inherited) jdk1.5起开始提供了4个元注解,用来定义自定义注解的注解,它们 ...

  10. Spring 注解@Value详解

    一.spring(基础10) 注解@Value详解[1] 一 配置方式 @value需要参数,这里参数可以是两种形式: [html] view plaincopy @Value("#{con ...

最新文章

  1. matlab四条曲线围成面,matlab中怎么给四条曲线作出图例啊?求大神指导
  2. Qt Creator启动调试器
  3. java中的json_java中的json使用
  4. 深入理解Solidity
  5. 相互引用的初始化过程
  6. 超强!MDETR:基于Transformer的端到端目标检测神器!开源!
  7. SAP-R3被取代,苏宁采购平台的升级和架构演进之路
  8. 开发smartphone应用,无法生成cab文件?
  9. fiddler限速/弱网模拟
  10. 好看流光风格个人主页源码
  11. 热血江湖Java_热血江湖源码+教程
  12. 【数据结构】约瑟夫问题
  13. 用飞桨,为少数民族濒危语言生成一本词典
  14. cmt obm odm 代工模式oem_OEM、ODM、OBM、OPM概念,作用与区别
  15. malformed header from script. Bad header的解决方法以及原因
  16. ibm是被联想收购了吗_联想的现状,让人不得不佩服当年IBM的老辣
  17. curl命令介绍与使用
  18. css中横线中间显示文字
  19. 如何让Markdown 表格整体居中?
  20. 刀片服务器虚拟交换机,web client6.0设置刀片服务器虚拟机网络

热门文章

  1. sicily 1282. Computer Game
  2. XML入门的常见问题
  3. go学习笔记-运算符
  4. Spring Cloud Sleuth 使用教程
  5. 【maven】maven pom文件详解
  6. 坑爹的libxml2 for mingw 编译
  7. 用户调用机房收费下机中用到的策略与职责链解析
  8. Oracle笔记(九) 表的创建及管理
  9. Chrome Frame
  10. Kafka Consumer API示例