|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ebmwebsourcing.easycommons.lang.reflect.ReflectionHelper
public final class ReflectionHelper
| Method Summary | ||
|---|---|---|
static Set<Class<?>> |
findAllImplementedInterfaces(Class<?> clazz)
Find all implemented interfaces recursively. |
|
static Collection<Method> |
findMethodsThatReturnType(Class<?> clazz,
Class<?> returnType)
|
|
static Method |
getDeclaredMethod(Class<?> clazz,
String methodName,
Class<?>... parameterTypes)
Get a declared method and wrap exceptions into unchecked exceptions. |
|
static Object |
getFieldValue(Object obj,
Field field)
|
|
static Object |
getPrivateFieldValue(Class<?> clazz,
Object instance,
String fieldName)
|
|
static List<Method> |
getPublicDeclaredMethods(Class<?> clazz)
Get all public declared methods and wrap exceptions into unchecked exceptions. |
|
static Method |
getPublicMethod(Class<?> clazz,
String methodName,
Class<?>... parameterTypes)
Get a public method and wrap exceptions into unchecked exceptions. |
|
static Object |
invokeMethod(Object obj,
Method method,
Object... args)
Invoke a method by reflection. |
|
static Object |
invokePrivateMethod(Class<?> clazz,
Object obj,
String methodName,
Object[] args,
Class<?>[] types)
Invoke a private method by reflection. |
|
static Object |
invokePrivateMethod(Object obj,
String methodName,
Object... args)
Deprecated. Does not work correctly with private methods having parameter as List. Replaced by
#invokePrivateMethod(Object, String, Object[], Object[]) |
|
static Object |
invokePrivateMethod(Object obj,
String methodName,
Object[] args,
Class<?>[] types)
Invoke a private method of an object instance, by reflection. |
|
static boolean |
isOrInheritedFrom(Class<?> clazz,
String canonicalName)
Test if the specified class is or inherited from the class with the specified canonical name |
|
static
|
loadClass(String className,
ClassLoader cl)
|
|
static
|
newInstance(Class<T> clazz,
Object... args)
|
|
static
|
newInstance(String className,
ClassLoader cl,
Object... args)
|
|
static void |
setFieldValue(Object obj,
Field field,
Object newValue)
|
|
static void |
setPrivateField(Object obj,
String fieldName,
Object value)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static final Set<Class<?>> findAllImplementedInterfaces(Class<?> clazz)
clazz - Class for which we want to know all implemented interfaces.
public static final Method getPublicMethod(Class<?> clazz,
String methodName,
Class<?>... parameterTypes)
clazz - methodName - parameterTypes -
public static final List<Method> getPublicDeclaredMethods(Class<?> clazz)
clazz -
public static final Method getDeclaredMethod(Class<?> clazz,
String methodName,
Class<?>... parameterTypes)
clazz - methodName - parameterTypes -
public static final Object invokeMethod(Object obj,
Method method,
Object... args)
throws InvocationTargetException
obj - Object on which to invoke method.method - Method to be invoked.args - Method arguments.
InvocationTargetException
@Deprecated
public static final Object invokePrivateMethod(Object obj,
String methodName,
Object... args)
throws InvocationTargetException
List. Replaced by
#invokePrivateMethod(Object, String, Object[], Object[])
obj - Object on which to invoke method.method - Method to be invoked.args - Method arguments.
InvocationTargetException
public static final Object invokePrivateMethod(Object obj,
String methodName,
Object[] args,
Class<?>[] types)
throws InvocationTargetException
obj - Object on which to invoke method.method - Method to be invoked.args - Method arguments.types - Method argument types.
InvocationTargetException
public static final Object invokePrivateMethod(Class<?> clazz,
Object obj,
String methodName,
Object[] args,
Class<?>[] types)
throws InvocationTargetException
clazz - The class of the object obj, can be
null if the private method is not static.obj - Object on which to invoke method. Is null if the
private method to invoke is static.method - Method to be invoked.args - Method arguments.types - Method argument types.
InvocationTargetException
public static final <T> T newInstance(Class<T> clazz,
Object... args)
throws InvocationTargetException
InvocationTargetException
public static final <T> T newInstance(String className,
ClassLoader cl,
Object... args)
throws InvocationTargetException
InvocationTargetException
public static final <T> Class<T> loadClass(String className,
ClassLoader cl)
public static final Collection<Method> findMethodsThatReturnType(Class<?> clazz,
Class<?> returnType)
public static final Object getPrivateFieldValue(Class<?> clazz,
Object instance,
String fieldName)
public static final Object getFieldValue(Object obj,
Field field)
public static void setPrivateField(Object obj,
String fieldName,
Object value)
throws IllegalArgumentException
IllegalArgumentException
public static final void setFieldValue(Object obj,
Field field,
Object newValue)
public static final boolean isOrInheritedFrom(Class<?> clazz,
String canonicalName)
clazz - the class to checksuperClassName - the class name to look for
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||