public class ReflectUtil
extends cn.hutool.core.util.ReflectUtil
| 构造器和说明 |
|---|
ReflectUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static RuntimeException |
convertReflectionExceptionToUnchecked(String msg,
Exception e)
将反射时的checked exception转换为unchecked exception.
|
static Field |
getAccessibleField(Object obj,
String fieldName)
循环向上转型, 获取对象的DeclaredField, 并强制设置为可访问.
|
static Method |
getAccessibleMethod(Object obj,
String methodName,
Class<?>... parameterTypes)
循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
|
static Method |
getAccessibleMethodByName(Object obj,
String methodName,
int argsNum)
循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
|
static <T> Class<T> |
getClassGenricType(Class clazz)
通过反射, 获得Class定义中声明的泛型参数的类型, 注意泛型必须定义在父类处
如无法找到, 返回Object.class.
|
static Class |
getClassGenricType(Class clazz,
int index)
通过反射, 获得Class定义中声明的父类的泛型参数的类型.
|
static Class<?> |
getUserClass(Object instance) |
static <E> E |
invokeGetter(Object obj,
String propertyName)
调用Getter方法.
|
static <E> E |
invokeMethod(Object obj,
String methodName,
Class<?>[] parameterTypes,
Object[] args)
直接调用对象方法, 无视private/protected修饰符.
|
static <E> E |
invokeMethodByName(Object obj,
String methodName,
Object[] args)
直接调用对象方法, 无视private/protected修饰符,
用于一次性调用的情况,否则应使用getAccessibleMethodByName()函数获得Method后反复调用.
|
static <E> void |
invokeSetter(Object obj,
String propertyName,
E value)
调用Setter方法, 仅匹配方法名。
|
static void |
makeAccessible(Field field)
改变private/protected的成员变量为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
|
static void |
makeAccessible(Method method)
改变private/protected的方法为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
|
getConstructor, getConstructors, getConstructorsDirectly, getField, getFieldMap, getFieldName, getFields, getFields, getFieldsDirectly, getFieldsValue, getFieldValue, getFieldValue, getMethod, getMethod, getMethodByName, getMethodByName, getMethodByNameIgnoreCase, getMethodIgnoreCase, getMethodNames, getMethodOfObj, getMethods, getMethods, getMethodsDirectly, getPublicMethod, getPublicMethodNames, getPublicMethods, getPublicMethods, getPublicMethods, getPublicMethods, getStaticFieldValue, hasField, invoke, invoke, invokeStatic, invokeWithCheck, isEmptyParam, isEqualsMethod, isHashCodeMethod, isToStringMethod, newInstance, newInstance, newInstanceIfPossible, setAccessible, setFieldValue, setFieldValuepublic static <E> E invokeGetter(Object obj, String propertyName)
public static <E> void invokeSetter(Object obj, String propertyName, E value)
public static <E> E invokeMethod(Object obj, String methodName, Class<?>[] parameterTypes, Object[] args)
public static <E> E invokeMethodByName(Object obj, String methodName, Object[] args)
public static Field getAccessibleField(Object obj, String fieldName)
public static Method getAccessibleMethod(Object obj, String methodName, Class<?>... parameterTypes)
public static Method getAccessibleMethodByName(Object obj, String methodName, int argsNum)
public static void makeAccessible(Method method)
public static void makeAccessible(Field field)
public static <T> Class<T> getClassGenricType(Class clazz)
public static Class getClassGenricType(Class clazz, int index)
public static RuntimeException convertReflectionExceptionToUnchecked(String msg, Exception e)
Copyright © 2021. All rights reserved.