概念

1、表示抑制警告,这个注解的用处是忽略警告信息。

2、作用为告诉编译器忽略指定的警告,不用在编译完成后出现警告信息。

方法

deprecation ,忽略过时

rawtypes ,忽略类型安全

unused , 忽略不使用

unchecked ,忽略安全检查

null,忽略空

all,忽略所有

实例

//#3 抑制警告
// serial : 实现序列号接口,但没有生产序列号
@SuppressWarnings("serial")class Parent1_4 implements java.io.Serializable{
//null:空指针
@SuppressWarnings("null")
public void init(){
     //rawtypes:类型安全,没有使用泛型
     //unused : 不使用
    @SuppressWarnings({ "rawtypes", "unused" })
    List list = new ArrayList();
    String str = null;
    str.toString();
     }
}
登录后复制

以上就是如何在Java中使用@SuppressWarnings?的详细内容,更多请关注Work网其它相关文章!

08-22 08:05