public class ReflexUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
GET_PREFIX |
static String |
IS_PREFIX |
static String |
SET_PREFIX |
| 限定符和类型 | 方法和说明 |
|---|---|
static Field |
findField(Class<?> targetClass,
String fieldName)
从指定类中获取属性
|
static <T> T |
findFromClass(Class<?> targetClass,
Function<Class<?>,T[]> targetMapping,
Predicate<T> predicate)
从类及其父类中寻找指定的元素
|
static Method |
findGetterMethod(Class<?> targetClass,
Field field)
从指定类及其父类中寻找指定属性的getter方法
优先寻找格式为“getFieldName”,并且没有参数的方法;
若找不到,再寻找格式为“isFieldName”,并且没有参数的方法;
仍然找不到,再寻找格式为“fieldName”,并且没有参数的方法;
|
static Method |
findGetterMethod(Class<?> targetClass,
String fieldName)
从指定类及其父类中寻找指定属性的getter方法
优先寻找格式为“getFieldName”,并且没有参数的方法;
若找不到,再寻找格式为“isFieldName”,并且没有参数的方法;
仍然找不到,再寻找格式为“fieldName”,并且没有参数的方法;
|
static Method |
findMethod(Class<?> targetClass,
String methodName,
boolean allowSubclasses,
Class<?> returnType,
Class<?>... paramTypes)
从类中查找指定方法
|
static Optional<BeanProperty> |
findProperty(Class<?> targetClass,
String fieldName)
获取字段缓存
|
static Method |
findSetterMethod(Class<?> targetClass,
Field field)
从指定类及其父类中寻找指定属性的setter方法
优先寻找格式为“setFieldName”,并且有且仅有一个类型为fieldType的方法;
若找不到,再寻找格式为“fieldName”,并且有且仅有一个类型为fieldType的方法;
|
static Method |
findSetterMethod(Class<?> targetClass,
String fieldName,
Class<?> fieldType)
从指定类及其父类中寻找指定属性的setter方法
优先寻找格式为“setFieldName”,并且有且仅有一个类型为fieldType的方法;
若找不到,再寻找格式为“fieldName”,并且有且仅有一个类型为fieldType的方法;
|
static <T> void |
forEachFromClass(Class<?> targetClass,
Function<Class<?>,T[]> targetMapping,
Consumer<T> consumer)
从类及其父类中操作指定的元素
|
@Nullable public static Method findMethod(Class<?> targetClass, String methodName, boolean allowSubclasses, Class<?> returnType, Class<?>... paramTypes)
targetClass - 类methodName - 方法名称allowSubclasses - 参数类型是否允许子类returnType - 返回值类型paramTypes - 参数类型public static Optional<BeanProperty> findProperty(Class<?> targetClass, String fieldName)
targetClass - 类fieldName - 属性名IllegalArgumentException - 当属性存在,而却找不到对应setter与getter方法时抛出@Nullable public static Field findField(Class<?> targetClass, String fieldName)
targetClass - 类fieldName - 属性名@Nullable public static Method findSetterMethod(Class<?> targetClass, String fieldName, Class<?> fieldType)
targetClass - 属性fieldName - 属性名@Nullable public static Method findSetterMethod(Class<?> targetClass, Field field)
targetClass - 类field - 属性@Nullable public static Method findGetterMethod(Class<?> targetClass, String fieldName)
targetClass - 类fieldName - 属性名@Nullable public static Method findGetterMethod(Class<?> targetClass, Field field)
targetClass - 类field - 属性public static <T> void forEachFromClass(Class<?> targetClass, Function<Class<?>,T[]> targetMapping, Consumer<T> consumer)
targetClass - 类targetMapping - 指定元素的映射方法consumer - 操作Copyright © 2022. All rights reserved.