public final class ReflectionUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Constructor<?> |
getConstructor(Class<?> clazz,
Class<?>... arguments) |
static Method |
getMethod(Class<?> clazz,
String methodName,
Class<?>... parameters) |
static Method |
getMethod(Object instance,
String methodName,
Class<?>... parameters) |
static <T> T |
instantiate(ClassLoader classLoader,
String classname,
Class<T> returnType) |
static <T> T |
instantiateObject(String className,
Class<?>[] types,
Object[] params,
ClassLoader cl) |
static <T> T |
instantiateOneArg(ClassLoader classLoader,
String className,
Class<?> param1Class,
Object param1) |
static <T> T |
invokeGetter(Class<?> instanceType,
Object instance,
String methodName) |
static <T> T |
invokeGetter(Object instance,
String methodName) |
static <T> T |
invokeMethodChain(Class<?>[] classesChain,
String[] noArgMethodNames,
Object fallback)
Method chain invoker.
|
static <T> T |
invokeMethodWithArray(Object target,
Method method,
Object... args) |
static <T> T |
invokeMethodWithArray2(Object target,
Method method,
Object... args) |
static <T> T |
invokeSetter(Object target,
Method method,
Object value) |
static void |
invokeSetter(Object o,
String name,
Class<?> value1clazz,
Object value) |
static <T> T |
invokeStaticMethod(Class<?> clazz,
String methodName,
Class<?>[] parameterTypes,
Object[] parameters)
Invoker of public static no-argument method.
|
static Class<?> |
loadClass(ClassLoader classLoader,
String className) |
static <T> T |
newInstance(Constructor<?> constructor,
Object... params) |
static Class<?> |
reloadClass(ClassLoader classLoader,
Object source) |
static <T> Constructor<T> |
tryGetConstructor(Class<T> clazz,
Class<?>... arguments) |
static Method |
tryGetMethod(Class<?> clazz,
String methodName,
Class<?>... parameters) |
static Class<?> |
tryLoadClass(ClassLoader classLoader,
String className) |
public static Method getMethod(Object instance, String methodName, Class<?>... parameters)
public static Method tryGetMethod(Class<?> clazz, String methodName, Class<?>... parameters)
public static <T> T invokeGetter(Class<?> instanceType, Object instance, String methodName)
public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... arguments)
public static <T> Constructor<T> tryGetConstructor(Class<T> clazz, Class<?>... arguments)
public static <T> T newInstance(Constructor<?> constructor, Object... params)
public static <T> T instantiate(ClassLoader classLoader, String classname, Class<T> returnType)
public static <T> T instantiateOneArg(ClassLoader classLoader, String className, Class<?> param1Class, Object param1)
public static void invokeSetter(Object o, String name, Class<?> value1clazz, Object value)
public static <T> T invokeMethodWithArray(Object target, Method method, Object... args)
public static <T> T invokeMethodWithArray2(Object target, Method method, Object... args) throws InvocationTargetException
InvocationTargetException
public static <T> T instantiateObject(String className, Class<?>[] types, Object[] params, ClassLoader cl)
public static Class<?> tryLoadClass(ClassLoader classLoader, String className)
public static Class<?> loadClass(ClassLoader classLoader, String className)
public static Class<?> reloadClass(ClassLoader classLoader, Object source) throws ReflectiveOperationException
ReflectiveOperationException
public static <T> T invokeStaticMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes, Object[] parameters)
clazz
- class on which public static no-argument methodName
is invokedmethodName
- public static no-argument method to be calledparameterTypes
- method parameter typesparameters
- method parametersmethodName
RuntimeException
- if no such method foundSurefireReflectionException
- if the method could not be called or threw an exception.
It has original cause Exception.public static <T> T invokeMethodChain(Class<?>[] classesChain, String[] noArgMethodNames, Object fallback)
classesChain
- classes to invoke on method chainnoArgMethodNames
- chain of public methods to callfallback
- returned value if a chain could not be invoked due to an errorfallback
otherwiseIllegalArgumentException
- if classes
and noArgMethodNames
have different array lengthCopyright © 2004–2024 The Apache Software Foundation. All rights reserved.