public class ReflectionUtils extends Object
Constructor | Description |
---|---|
ReflectionUtils() |
Modifier and Type | Method | Description |
---|---|---|
static void |
call(Object thisObject,
String methodName) |
Helper method to call a no argument, no return method.
|
static Object |
callAny(Object thisObject,
String methodName,
Class<?>[] argTypes,
Object[] args) |
Helper method to call a multi-argument method having a return.
|
static Object |
callAny(Object thisObject,
String methodName,
Object[] args) |
Helper method to call a multi-argument method having a return.
|
static Object |
callAnyWithoutException(Object thisObject,
Class<?> objectClass,
String methodName,
Class<?>[] argTypes,
Object[] args) |
Helper method to call a multi-argument method having a return without throwing an exception.
|
static Object |
callConstructor(Class<?> clazz,
Class<?>[] argTypes,
Object[] args) |
Helper method to call a constructor.
|
static Object |
callGet(Object thisObject,
String methodName) |
Helper method to call a get method with no argument.
|
static void |
callSet(Object thisObject,
String methodName,
Object value) |
Helper method to call a set boolean method.
|
static void |
callSetBoolean(Object thisObject,
String methodName,
boolean value) |
Helper method to call a set boolean method.
|
static void |
callSetInt(Object thisObject,
String methodName,
int value) |
Helper method to call a set boolean method.
|
static Object |
callStatic(Class<?> thisClass,
String methodName,
Class<?>[] argTypes,
Object[] args) |
Helper method to call a multi-argument static class method having a return.
|
static Object |
createInstance(String className,
Class<?>[] types,
Object[] args) |
Instantiate an object based on the class name.
|
static boolean |
isSubClassOf(Object o,
String className) |
Checks if the instance o is an instance of a subclass of the designated class name.
|
public static void callSetBoolean(Object thisObject, String methodName, boolean value) throws Exception
thisObject
- the instancemethodName
- the method namevalue
- true or falseException
- if the method is not found or invocation to the method fails.public static void callSetInt(Object thisObject, String methodName, int value) throws Exception
thisObject
- the instancemethodName
- the method namevalue
- the valueException
- if the method is not found or invocation to the method fails.public static void callSet(Object thisObject, String methodName, Object value) throws Exception
thisObject
- the instancemethodName
- the method namevalue
- the valueException
- if the method is not found or invocation to the method fails.public static Object callGet(Object thisObject, String methodName) throws Exception
thisObject
- the instancemethodName
- the method nameException
- if the method is not found or invocation to the method fails.public static void call(Object thisObject, String methodName) throws Exception
thisObject
- the instancemethodName
- the method nameException
- if the method is not found or invocation to the method fails.public static Object callConstructor(Class<?> clazz, Class<?>[] argTypes, Object[] args) throws Exception
clazz
- the classargTypes
- argument Classes for constructor lookup. Must not be null.args
- the argument arrayException
- if the method is not found or invocation to the method fails.public static Object callAny(Object thisObject, String methodName, Object[] args) throws Exception
callAny(Object, methodName, argTypes, args)
.thisObject
- the instancemethodName
- the method nameargs
- the argument array, must not contain null.Exception
- if the method is not found or invocation to the method fails.public static Object callAny(Object thisObject, String methodName, Class<?>[] argTypes, Object[] args) throws Exception
thisObject
- the instancemethodName
- the method nameargTypes
- argument Classes for constructor lookup. Must not be null.args
- the argument arrayException
- if the method is not found or invocation to the method fails.public static Object callAnyWithoutException(Object thisObject, Class<?> objectClass, String methodName, Class<?>[] argTypes, Object[] args)
thisObject
- the instanceobjectClass
- the class which could find the method namemethodName
- the method nameargTypes
- argument Classes for constructor lookup. Must not be null.args
- the argument arraypublic static Object callStatic(Class<?> thisClass, String methodName, Class<?>[] argTypes, Object[] args) throws Exception
thisClass
- the classmethodName
- the method nameargTypes
- argument Classes for constructor lookup. Must not be null.args
- the argument arrayException
- if the method is not found or invocation to the method fails.public static Object createInstance(String className, Class<?>[] types, Object[] args)
className
- the class nametypes
- the class types for the constructorargs
- the constructor valuespublic static boolean isSubClassOf(Object o, String className)
o
- the instance to checkclassName
- the class name to check