Java Class getAnnotationsByType() 方法

2025年3月21日 | 阅读 1 分钟

java Class 类的 getAnnotationsByType() 方法按类型获取与此元素关联的注解。如果此元素没有关联的注解,则返回长度为 0 的数组。

语法

参数

annotationClass - 对应注解类型的 Class 对象

返回值

与此元素关联的注解类型,否则返回长度为零的数组。

抛出

NullPointerException

示例 1

输出

[@java.lang.Deprecated()]

示例 2

输出

MySuperClass Constructor Executing...
subClass Constructor Executing...
[@java.lang.Deprecated()]
[@ClassgetAnnotationsByteExample2$Annotation1()]
 
下一个主题Java类