`

@SuppressWarnings的使用、作用、用法(转)

    博客分类:
  • java
 
阅读更多
在java编译过程中会出现很多警告,有很多是安全的,但是每次编译有很多警告影响我们对error的过滤和修改,我们可以在代码中加上

@SuppressWarnings(“XXXX”) 来解决

例如:@SuppressWarnings("deprecation")表示不显示使用了不赞成使用的类或方法时的警告

具体的XXXX的意义可以参考博文

http://www.thebuzzmedia.com/supported-values-for-suppresswarnings/


Update #1: All these annotations are still valid in Eclipse 3.4 and 3.5, there have been no new SuppressWarning arguments added in those versions of the JDT compiler.

If you are a Java developer and use the new @SuppressWarnings annotation in your code from time-to-time to suppress compiler warnings you, like me, have wondered probably about a million times alreadyjust exactly what are the supported values that can be used with this annotation.

The reason the list isn’t easy to find is because it’s compiler specific, which means Sun may have a different set of supported values than say IBM, GCJ or Apache Harmony.

Fortunately for us, the Eclipse folks have documented the values they support (As of Eclipse 3.3), here they are for reference:

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

    )下面是一个清单: 关键字 用途 deprecation 使用了不赞成使用的类或方法时的警告 unchecked 执行了未检查的转换时的警告,例如当使用集合时没有用泛型 (Generics) 来指定集合保存的类型。 fallthrough 当 Switch ...

    Java注释@interface的用法

    @Override,@Deprecated,@SuppressWarnings为常见的3个注解。 注解相当于一种标记,在程序中加上了注解就等于为程序加上了某种标记,以后, JAVAC编译器,开发工具和其他程序可以用反射来了解你的类以及各种元素上...

    观看韩顺平学习整理java的笔记到异常

    类方法使用注意事项和细节讨论 4 main()方法 4 代码块 4 代码块使用注意事项和细节 5 单例模式 6 final关键字 6 抽象类 8 抽象类--模板设计模式 9 接口 9 内部类 11 匿名内部类的使用(重要!!!!!!!) 13 成员内部类的...

    ibatis例子=》包含了常用方法介绍

    包含SqlMapClient里全部方法的介绍,附带了数据库,绝对的原创,本资源绝对的免费 /* * 带参数的queryForMap用法 */ @SuppressWarnings("unchecked") public Map queryForMap(String sql_name, Object ...

    LinkedList的用法

    @SuppressWarnings("unchecked") public static void main(String[] args) { LinkedList<String> list = new LinkedList(); list.add("aaa"); list.add("bbb"); list.add("ccc"); /* * public ...

    JPA 和 注释文档

    作用:使接口、类、方法过时 注释: @Deprecated 2) 消除感叹号 修饰对象:有感叹号 作用:消除感叹号 注释:@SuppressWarnings(value={"unchecked"}) 注意: 如果注释的属性名为 value 且只有一属性,则使用...

    注解

    给程序说,用于解释代码,java中类,方法,变量,参数和包都能被标注,通过反射获取标注呢容,JDK1.5之后的特征,用于说明程序,在框架中使用 格式:@AnnotationName 作用 代码中生成JavaDOC API文档 -encoding utf-...

    JavaSE-注解与反射(框架底层实现机制)

    @Override:重写方法 @Deprecated:废弃 @SuppressWarnings:镇压警告 元注解(meta-annotation): 可自定义注解 @Target:描述注解的使用范围,传入value参数指定 @Retention:描述注解的生命周期,传入value参数...

    Java使用反射调用方法

    在使用反射可以得到类模板class对象,那么得到类模板的class对象后,如何调用某个已知的且需要的方法呢?答案是使用method类的invoke方法,那么实现的代码如下,结合jdk的api和该代码便可以知道原理 package ...

    java中注解的使用与实例

     @Override,表示当前的方法定义将覆盖超类中的方法。  @Deprecated,使用了注解为它的元素编译器将发出警告,因为注解@Deprecated是不赞成使用的代码,被弃用的代码。  @SuppressWarnings,关闭不当编译器...

    Java常用内置注解用法分析

    主要介绍了Java常用内置注解用法,结合实例形式分析了java使用@SuppressWarnings关闭警告信息以及@Depreca标注的元素不使用两种注解使用方法,需要的朋友可以参考下

    java用线程两种方式

    * 分别使用Runnable接口和Thread类编程实 编写一应用程序创建两个线程一个线程打印输出1—1000之间所有的奇数(Odd Number) * 另外一个线程打印输出1-1000之间所有的偶数(Even Number)要求两个线程随机休眠一 段...

    Java版水果管理系统源码-huihe_2020summer:2020假期spring学习,vue留给你们了,有兴趣自己可以看官方文档,中文很

    如果使用该方法,会报编译警告。 @SuppressWarnings - 指示编译器去忽略注解中声明的警告。 作用在其他注解的注解(或者说 元注解)是: @Retention - 标识这个注解怎么保存,是只在代码中,还是编入class文件中,或者...

    ext-gson:Google Gson扩展

    没有捆绑或计划捆绑ext-gson依赖项,因此应该将所有依赖项与provided作用域一起添加。 介绍了什么 当前ext-gson支持: JsonReader和JsonWriter的次要实用程序方法。 JsonElement静态工厂方法和生成器, ...

    java鼠标监听器源码-vaadincanvas:Vaadin的HTML5Canvas插件

    java鼠标监听器源码Vaadin 的 ...Canvas 插件 这是一个 Vaadin 插件,增加了对 ...画布的支持。...您将Canvas组件添加到 ...UI,然后可以使用服务器端代码...@SuppressWarnings ( " serial " ) @Theme ( " valo " ) @Widgetset (

    JSF2.xdatatable分页控件与左侧菜单最简单应用

    一、分页具体使用方法如下(不多说,直接给你些颜色看看): 1. xhtml文件:   <html xmlns:ems="http://www.ems.com.cn" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"...

    JSF2datatable分页控件与左侧菜单

    下面帖我的控件的使用方法:  下载地址:http://download.csdn.net/detail/ptianfeng/4802713 一、分页具体使用方法如下(不多说,直接给你些颜色看看): 1. xhtml文件:   <html xmlns:ems=...

    Android中Spinner控件之键值对用法实例分析

    本文实例讲述了Android中Spinner控件之键值对用法。分享给大家供大家参考。具体如下: 一、字典表,用来存放键值对信息 package com.ljq.activity; import java.io.Serializable; @SuppressWarnings(serial) public...

    疯狂JAVA讲义

    学生提问:hashCode方法对于HashSet的作用是什么? 249 7.3.2 TreeSet类 252 7.3.3 EnumSet类 259 7.4 List接口 261 7.4.1 List接口和ListIterator接口 261 7.4.2 ArrayList和Vector实现类 264 7.4.3 固定长度...

    \java超强笔记(超级经典)

    @SuppressWarnings 注释类或方法,忽略其中的某些类型的警告信息 注释的三种类型: 标记注释:不需要任何参数 @Override @Deprecated 单值注释:有一个值的注释 @注释名(值名=值) ...

Global site tag (gtag.js) - Google Analytics