首页  >  文章  >  Java  >  如何在Java中使用@SuppressWarnings?

如何在Java中使用@SuppressWarnings?

WBOY
WBOY转载
2023-04-21 08:01:061003浏览

概念

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?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:yisu.com。如有侵权,请联系admin@php.cn删除