public abstract class ReflectionUtils extends Object
ReflectionUtils
Modifier and Type | Class and Description |
---|---|
static class |
ReflectionUtils.InvocationCheckedExceptionWrapper
Runtime exception wrapper for checked exceptions thrown by invoked
methods.
|
Constructor and Description |
---|
ReflectionUtils() |
Modifier and Type | Method and Description |
---|---|
static Exception |
getInvocationException(Exception exception)
Analyze the given exception and, if it's of type
ReflectionUtils.InvocationCheckedExceptionWrapper then will return the actual
cause, otherwise return the original exception given. |
static void |
handleInvocationTargetException(InvocationTargetException ex)
Handle the given invocation target exception.
|
static Object |
invokeMethod(Method method,
Object target)
Invoke the specified
Method against the supplied target object
with no arguments. |
static Object |
invokeMethod(Method method,
Object target,
Object[] args)
Invoke the specified
Method against the supplied target object
with the supplied arguments. |
public static Object invokeMethod(Method method, Object target)
Method
against the supplied target object
with no arguments. The target object can be null
when
invoking a static Method
.
This method is identical to
ReflectionUtils.invokeMethod(Method, Object)
except that if the target method throws a checked exception, the method
will throw a InvocationCheckedException.
Thrown exceptions are handled via a call to
#handleReflectionException
.
method
- the method to invoketarget
- the target object to invoke the method oninvokeMethod(java.lang.reflect.Method, Object, Object[])
public static Object invokeMethod(Method method, Object target, Object[] args)
Method
against the supplied target object
with the supplied arguments. The target object can be null
when invoking a static Method
.
This method is identical to
ReflectionUtils.invokeMethod(Method, Object)
except that if the target method throws a checked exception, the method
will throw a InvocationCheckedException.
Thrown exceptions are handled via a call to
#handleReflectionException
.
method
- the method to invoketarget
- the target object to invoke the method onargs
- the invocation arguments (may be null
)invokeMethod(java.lang.reflect.Method, Object, Object[])
public static void handleInvocationTargetException(InvocationTargetException ex)
Throws the underlying RuntimeException or Error in case of such a root
cause. Throws an InvocationCheckedException else (the main difference
from
ReflectionUtils.handleInvocationTargetException(InvocationTargetException)
.
ex
- the invocation target exception to handlepublic static Exception getInvocationException(Exception exception)
ReflectionUtils.InvocationCheckedExceptionWrapper
then will return the actual
cause, otherwise return the original exception given.exception
- invocation exceptionCopyright © 2006–2016. All rights reserved.