public abstract class ReflectionUtils extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
ReflectionUtils.ClassFields |
static class |
ReflectionUtils.ClassMethods |
static class |
ReflectionUtils.ScanDirection |
| 构造器和说明 |
|---|
ReflectionUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T extends Annotation> |
findAnnotation(AnnotatedElement element,
Class<T> annotationType) |
static <T extends Annotation> |
findAnnotations(AnnotatedElement element,
Class<T> annotationType) |
static String |
generateKey(Class<?> type,
String methodName,
Class<?>... parameterTypes) |
static String |
generateKey(String methodName,
Class<?>... parameterTypes) |
static String |
generateMethodKey(Method method) |
static ReflectionUtils.ClassFields |
getAllField(Class<?> type)
获取所有的属性(包含私有属性,但不包含final和static修饰的属性)
|
static ReflectionUtils.ClassFields |
getAllField(Class<?> type,
ReflectionUtils.ScanDirection direction) |
static ReflectionUtils.ClassMethods |
getAllMethod(Class<?> type)
获取所有的方法(包含私有方法,但不包含abstract和static修饰的方法)
|
static ReflectionUtils.ClassMethods |
getAllMethod(Class<?> type,
ReflectionUtils.ScanDirection direction)
获取所有的方法(包含私有方法,但不包含abstract和static修饰的方法)
|
static <T extends Annotation> |
getAnnotation(AnnotatedElement element,
Class<T> annotationType) |
static <T extends Annotation> |
getAnnotations(AnnotatedElement element,
Class<T> annotationType) |
static Object |
getComplexValue(Object target,
String complexFieldName)
获取对象某个字段的值
|
static Object |
getComplexValue(Object target,
String complexFieldName,
String separator)
获取对象某个字段的值
|
static Constructor<?>[] |
getConstructors(Class<?> type) |
static Constructor<?>[] |
getDeclaredConstructors(Class<?> type) |
static Constructor<?> |
getDefaultConstructor(Class<?> type) |
static Field |
getField(Class<?> type,
String fieldName) |
static ReflectionUtils.ClassFields |
getFields(Class<?> type)
获取所有的属性(不包含私有属性)
|
static Method |
getMethod(Class<?> type,
String methodName,
Class<?>... args) |
static String |
getMethodDescriptor(Method method) |
static ReflectionUtils.ClassMethods |
getMethods(Class<?> type)
获取所有的方法(不包含私有方法)
|
static String |
getTypeDescriptor(Class<?> type) |
static Object |
getValue(Object target,
Field field)
获取对象某个字段的值
|
static Object |
getValue(Object target,
String fieldName)
获取对象某个字段的值
|
static Object |
getValue(Object target,
String[] fieldNames)
获取对象某个字段的值
|
static boolean |
hasAnnotation(AnnotatedElement element,
Class<? extends Annotation>... annotationTypes) |
static boolean |
hasAnnotation(AnnotatedElement element,
Class<? extends Annotation> annotationType) |
static boolean |
hasAnnotationPresent(AnnotatedElement element,
Class<? extends Annotation>... annotationTypes) |
static Object |
invokeMethod(Method method,
Object instance,
Object... args) |
static boolean |
isAnnotationPresent(AnnotatedElement element,
Class<? extends Annotation> annotation) |
static void |
makeAccessible(Constructor<?> ctor)
使构造器可访问
|
static void |
makeAccessible(Field field)
使字段可访问
|
static void |
makeAccessible(Method method)
使方法可访问
|
static Object |
newInstance(Constructor<?> constructor,
Object... args) |
static Object |
setValue(Object target,
Field field,
Object value)
获取对象某个字段的值
|
static Object |
setValue(Object target,
String fieldName,
Object value)
给对象的某个字段赋值
|
public static void makeAccessible(@Nonnull Constructor<?> ctor)
ctor - 构造器public static Object newInstance(Constructor<?> constructor, Object... args)
public static ReflectionUtils.ClassMethods getAllMethod(@Nonnull Class<?> type)
type - 类型public static ReflectionUtils.ClassMethods getAllMethod(@Nonnull Class<?> type, ReflectionUtils.ScanDirection direction)
type - 类型direction - 扫描方向public static ReflectionUtils.ClassMethods getMethods(@Nonnull Class<?> type)
type - 类型public static Method getMethod(@Nonnull Class<?> type, String methodName, Class<?>... args)
public static Object invokeMethod(@Nonnull Method method, Object instance, Object... args)
public static ReflectionUtils.ClassFields getAllField(@Nonnull Class<?> type)
type - 类型public static ReflectionUtils.ClassFields getAllField(@Nonnull Class<?> type, ReflectionUtils.ScanDirection direction)
public static ReflectionUtils.ClassFields getFields(@Nonnull Class<?> type)
type - 类型public static Constructor<?>[] getDeclaredConstructors(@Nonnull Class<?> type)
public static Constructor<?>[] getConstructors(@Nonnull Class<?> type)
public static Constructor<?> getDefaultConstructor(@Nonnull Class<?> type)
public static Object getValue(@Nullable Object target, Field field)
target - 对象field - 字段public static Object getComplexValue(@Nonnull Object target, String complexFieldName)
target - 对象complexFieldName - 字段名称 以点"."拼接public static Object getComplexValue(@Nonnull Object target, String complexFieldName, String separator)
target - 对象complexFieldName - 字段名称separator - 字段分隔符public static Object getValue(@Nonnull Object target, String[] fieldNames)
target - 对象fieldNames - 字段名称数组public static Object getValue(@Nonnull Object target, String fieldName)
target - 对象fieldName - 字段名称public static Object setValue(@Nonnull Object target, String fieldName, Object value)
target - 对象fieldName - 字段名称value - 字段值public static Object setValue(@Nonnull Object target, Field field, Object value)
target - 对象field - 字段value - 字段值public static <T extends Annotation> T getAnnotation(@Nonnull AnnotatedElement element, Class<T> annotationType)
public static <T extends Annotation> List<T> getAnnotations(@Nonnull AnnotatedElement element, Class<T> annotationType)
public static <T extends Annotation> T findAnnotation(@Nonnull AnnotatedElement element, Class<T> annotationType)
public static <T extends Annotation> List<T> findAnnotations(@Nonnull AnnotatedElement element, Class<T> annotationType)
public static boolean isAnnotationPresent(@Nonnull AnnotatedElement element, Class<? extends Annotation> annotation)
public static boolean hasAnnotationPresent(@Nonnull AnnotatedElement element, Class<? extends Annotation>... annotationTypes)
public static boolean hasAnnotation(@Nonnull AnnotatedElement element, Class<? extends Annotation>... annotationTypes)
public static boolean hasAnnotation(@Nonnull AnnotatedElement element, Class<? extends Annotation> annotationType)
public static String generateKey(@Nonnull Class<?> type, String methodName, Class<?>... parameterTypes)
Copyright © 2025. All rights reserved.