public class AnnotationUtils extends Object
| 构造器和说明 |
|---|
AnnotationUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <A extends Annotation> |
findAnnotation(Class<?> clazz,
Class<A> annotationType)
获取 给定
Class的单个Annotations。 |
static <A extends Annotation> |
findAnnotation(Method method,
Class<A> annotationType)
获取 给定
Method的单个Annotations。 |
static <A extends Annotation> |
getAnnotation(Method method,
Class<A> annotationType)
获取 给定
Method的单个Annotations。 |
static Object |
getValue(Annotation annotation)
Retrieve the value of the
"value" attribute of a
single-element Annotation, given an annotation instance. |
static Object |
getValue(Annotation annotation,
String attributeName)
Retrieve the value of a named Annotation attribute, given an annotation instance.
|
public static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType)
Class的单个Annotations。
当根据类型从方法中未找到符合条件的Annotation时,遍历该类的父类或者接口进行查找。clazz - 被查询的classannotationType - 查找的annotation类型nullpublic static <A extends Annotation> A findAnnotation(Method method, Class<A> annotationType)
Method的单个Annotations。
当根据类型从方法中未找到符合条件的Annotation时,查找该方法所在类所实现的接口,看接口是否存在注解。method - 被查询的methodannotationType - 查找的annotation类型public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType)
Method的单个Annotations。
当根据类型从方法中未找到符合条件的Annotation时,可以通过查找其全部声明并进行类型比较处理。method - 被查询的methodannotationType - 查找的annotation类型public static Object getValue(Annotation annotation, String attributeName)
annotation - the annotation instance from which to retrieve the valueattributeName - the name of the attribute value to retrievenull if not foundgetValue(Annotation)public static Object getValue(Annotation annotation)
"value" attribute of a
single-element Annotation, given an annotation instance.annotation - the annotation instance from which to retrieve the valuenull if not foundgetValue(Annotation, String)Copyright © 2018. All rights reserved.