@SuppressWarnings注解主要用在取消一些编译器产生的警告

如图所示:
【加注解之前】
@SuppressWarnings 使用
【加注解之后】
@SuppressWarnings 使用


这时候我们在方法上加上@SuppressWarnings注解就可以消除这些警告的产生,注解的使用有三种:

  1. @SuppressWarnings(“unchecked”) [^ 抑制单类型的警告]
  2. @SuppressWarnings(“unchecked”,“rawtypes”) [^ 抑制多类型的警告]
  3. @SuppressWarnings(“all”) [^ 抑制所有类型的警告]

通过源码分析可知@SuppressWarnings其注解目标为类、字段、函数、函数入参、构造函数和函数的局部变量。建议把注解放在最近进警告发生的位置。
下面列举警告关键字:
@SuppressWarnings 使用

相关文章: