Java中@SuppressWarnings注解具有什么功能呢?
下文笔者讲述java中@SuppressWarnings注解的功能简介说明,如下所示
@SuppressWarnings注解功能简介
@SuppressWarnings注解功能:
告诉编译器忽略指定的警告,不用在编译完成后出现警告信息
@SuppressWarnings注解简介:
@SuppressWarnings注解是J2SE5.0中标准的Annotation之一
可标注在类、字段、方法、参数、构造方法,以及局部变量上
@SuppressWarnings注解的使用示例
@SuppressWarnings("unchecked")
编译器忽略 unchecked 警告信息
如使用list,ArrayList等未进行参数化产生的警告信息。
@SuppressWarnings("serial")
如果编译器出现这样的警告信息:
The serializable class WmailCalendar does notdeclare a static final serialVersionUID field of type long
使用这个注释将警告信息去掉。
@SuppressWarnings("deprecation")
如果使用@Deprecated注释的方法,编译器将出现警告信息
使用这个注释将警告信息去掉
@SuppressWarnings("unchecked", "deprecation")
告诉编译器同时忽略unchecked和deprecation的警告信息
@SuppressWarnings(value={"unchecked", "deprecation"})
可简写为@SuppressWarnings("unchecked", "deprecation")
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


