public class AnnotationUtils extends Object
Constructor and Description |
---|
AnnotationUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
cleanCache()
清除缓存
|
static <T extends Annotation> |
getAnnotation(AnnotatedElement from,
Class<T> annotationType)
从某个类上获取注解对象,注解可以深度递归
如果存在多个继承注解,则优先获取浅层第一个注解,如果浅层不存在,则返回第一个获取到的注解
请尽可能保证仅存在一个或者一种继承注解,否则获取到的类型将不可控
|
static <T extends Annotation> |
getAnnotation(AnnotatedElement from,
Class<T> annotationType,
Class<T>... ignored)
从某个类上获取注解对象,注解可以深度递归
如果存在多个继承注解,则优先获取浅层第一个注解,如果浅层不存在,则返回第一个获取到的注解
请尽可能保证仅存在一个或者一种继承注解,否则获取到的类型将不可控
|
static Beans |
getBeansAnnotationIfListen(Class<?> from)
尝试从一个类对象中获取到@Beans注解
|
static Method |
getConstrMethod(Class clz)
获取类中标注了@Constr注解的方法。
如果有多个,获取其中某一个;
如果出现了:
- 注解不存在静态方法上、
- 方法返回值不是这个类本身或者子类
则会抛出异常
|
static Depend |
getDepend(AnnotatedElement from)
获取Depend注解。
如果获取不到Depend, 则尝试获取
Resource |
public static Depend getDepend(AnnotatedElement from)
Resource
from
- public static Beans getBeansAnnotationIfListen(Class<?> from)
public static <T extends Annotation> T getAnnotation(AnnotatedElement from, Class<T> annotationType)
from
- 获取注解的某个类annotationType
- 想要获取的注解类型public static <T extends Annotation> T getAnnotation(AnnotatedElement from, Class<T> annotationType, Class<T>... ignored)
from
- 获取注解的某个类annotationType
- 想要获取的注解类型ignored
- 获取注解列表的时候的忽略列表public static Method getConstrMethod(Class clz)
clz
- class对象AnnotationException
- 如果不是静态方法、没有返回值、返回值不是这个类型或者这个类型的字类类型却使用了@Constr注解
便会抛出此异常
see lang:
public static void cleanCache()
Copyright © 2020. All rights reserved.