public class ReflectionUtil extends Object
| 构造器和说明 |
|---|
ReflectionUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static RuntimeException |
convertReflectionExceptionToUnchecked(Exception e)
将反射时的checked exception转换为unchecked exception.
|
static Object |
getFieldValue(Object object,
String fieldName)
直接读取对象属性值, 无视private/protected修饰符, 不经过getter函数.
|
static Class<?> |
getSuperClassGenricType(Class<?> clazz,
int index)
通过反射, 获得定义Class时声明的父类的泛型参数的类型.
|
static <T> Class<T> |
getSuperClassGenricType(Class<T> clazz)
通过反射, 获得Class定义中声明的父类的泛型参数的类型.
|
static Object |
invokeGetterMethod(Object object,
String fieldName)
调用Getter方法.
|
static Object |
invokeMethod(Object object,
String methodName,
Class<?>[] parameterTypes,
Object[] parameterValues)
直接调用对象方法, 无视private/protected修饰符.
|
static void |
invokeSetterMethod(Object target,
String fieldName,
Class<?> parameterType,
Object parameterValue)
调用Setter方法.
|
static void |
invokeSetterMethod(Object target,
String propertyName,
Object parameterValue)
调用Setter方法.使用value的Class来查找Setter方法.
|
static void |
setFieldValue(Object object,
String fieldName,
Object fieldValue)
直接设置对象属性值, 无视private/protected修饰符, 不经过setter函数.
|
public static Object getFieldValue(Object object, String fieldName)
object - fieldName - public static void setFieldValue(Object object, String fieldName, Object fieldValue)
object - fieldName - fieldValue - public static Object invokeMethod(Object object, String methodName, Class<?>[] parameterTypes, Object[] parameterValues)
object - methodName - parameterTypes - parameterValues - public static Object invokeGetterMethod(Object object, String fieldName)
object - fieldName - public static void invokeSetterMethod(Object target, String fieldName, Class<?> parameterType, Object parameterValue)
target - fieldName - parameterValue - parameterType - 用于查找Setter方法,为空时使用value的Class替代.public static void invokeSetterMethod(Object target, String propertyName, Object parameterValue)
target - propertyName - parameterValue - public static <T> Class<T> getSuperClassGenricType(Class<T> clazz)
T - clazz - public static Class<?> getSuperClassGenricType(Class<?> clazz, int index)
clazz - index - public static RuntimeException convertReflectionExceptionToUnchecked(Exception e)
Copyright © 2019. All rights reserved.