当前位置: 代码迷 >> 综合 >> Java中@SuppressWarnings(“unchecked“)注解的作用
  详细解决方案

Java中@SuppressWarnings(“unchecked“)注解的作用

热度:47   发布时间:2024-02-07 01:07:38.0

一、简介

java.lang.SuppressWarnings是J2SE5.0中标准的Annotation之一。可以标注在类、字段、方法、参数、构造方法,以及局部变量

二、注解的作用

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

三、使用方法

  • @SuppressWarnings(“”)
  • @SuppressWarnings({})
  • @SuppressWarnings(value={})

示例1:
@SuppressWarnings(“unchecked”)
告诉编译器忽略 unchecked 警告信息,如使用List,ArrayList等未进行参数化产生的警告信息

示例2:
@SuppressWarnings(“unchecked”, “deprecation”)
告诉编译器同时忽略unchecked和deprecation的警告信息

示例3:
@SuppressWarnings(value={“unchecked”, “deprecation”})
等同于@SuppressWarnings(“unchecked”, “deprecation”)

  相关解决方案