public class ReflectionUtil extends Object
| Constructor and Description |
|---|
ReflectionUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
copyDeclaredFields(Class<?> klass,
Object src,
Object dest) |
static Method |
findDeclaredMethod(Class<?> klass,
String methodName,
Object... args)
Find the single declared method in the class hierarchy that matches the name and parameters.
|
static Class<?> |
getClassForAnyName(ClassLoader loader,
String... names) |
static Constructor<?> |
getDeclaredConstructor(Class<?> klass,
Class<?>... paramTypes) |
static Field |
getDeclaredField(Class<?> klass,
String name) |
static Method |
getDeclaredMethod(Class<?> klass,
String method,
Class<?>... paramTypes) |
static <T> T |
getFieldValue(Class<?> orig,
String field) |
static <T> T |
getFieldValue(Object o,
String field) |
static <T> T |
invoke(Object target,
String methodName)
Invoke a declared method with no parameters
|
static <T> T |
invoke(Object target,
String methodName,
Object param1)
Invoke a declared method with one parameter.
|
static <T> T |
invoke(Object target,
String methodName,
Object param1,
Object param2)
Invoke a declared method with two parameters.
|
static <T> T |
invoke(Object target,
String methodName,
Object param1,
Object param2,
Object param3)
Invoke a declared method with three parameters.
|
static Object |
invokeByArgs(Object target,
String methodName,
Object... args) |
static Object |
invokeStaticByArgs(Class<?> klass,
String methodName,
Object... args) |
static void |
setAccessible(AccessibleObject m) |
static void |
setFieldValue(Object instance,
Class<?> klass,
String field,
Object value) |
static void |
setFieldValue(Object instance,
String field,
Object value) |
static void |
setFieldValueOrFail(Object instance,
Class<?> klass,
String field,
Object value) |
static void |
setFieldValueOrFail(Object instance,
String field,
Object value) |
public static <T> T invoke(Object target, String methodName, Object param1, Object param2, Object param3)
public static <T> T invoke(Object target, String methodName, Object param1, Object param2)
public static <T> T invoke(Object target, String methodName, Object param1)
public static <T> T invoke(Object target, String methodName)
public static Object invokeStaticByArgs(Class<?> klass, String methodName, Object... args)
public static Method findDeclaredMethod(Class<?> klass, String methodName, Object... args) throws NoSuchMethodException
NoSuchMethodExceptionpublic static void setFieldValueOrFail(Object instance, String field, Object value) throws Exception
Exceptionpublic static void setFieldValue(Object instance, Class<?> klass, String field, Object value)
public static void setFieldValueOrFail(Object instance, Class<?> klass, String field, Object value) throws Exception
instance - the instanceklass - lowest class in hierarchy to look into, restriction is needed when otherwise you might detect the same field name from unknown subclasses and change this insteadfield - the field namevalue - the new value of the fieldException - if field not setpublic static void setAccessible(AccessibleObject m)
public static Method getDeclaredMethod(Class<?> klass, String method, Class<?>... paramTypes)
public static Constructor<?> getDeclaredConstructor(Class<?> klass, Class<?>... paramTypes)
public static Class<?> getClassForAnyName(ClassLoader loader, String... names)
Copyright © 2018. All rights reserved.