public class ReflectionUtil extends Object
Constructor and Description |
---|
ReflectionUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
checkMatch(Class<?> parameterType,
Object arg) |
static Object |
constructNew(Class<?> clazz,
Object... args) |
static Map<String,Object> |
extractVariables(Object e)
extract all possible field values.
|
static Map<String,Object> |
extractVariablesWithEnumAsString(Object e) |
static List<String> |
getAllClasses(ClassLoader cl,
String packageName) |
static List<Field> |
getAllFields(List<Field> fields,
Class<?> c)
http://stackoverflow.com/questions/1042798/retrieving-the-inherited-attribute-names-values-using-java-reflection
|
static List<Field> |
getAllPublicFields(List<Field> fields,
Class<?> c) |
static List<Method> |
getAllPublicMethods(List<Method> methods,
Class<?> c) |
static Object |
getField(Class<?> clazz,
Object obj,
String fieldName) |
static Object |
getField(Object obj,
String fieldName) |
static Object |
invokeMethod(Class<?> clazz,
Object obj,
String methodName,
Object... args) |
static Object |
invokeMethod(Object obj,
String methodName,
Object... args) |
static void |
setField(Object obj,
String fieldName,
Object value) |
static void |
setFinalField(Class<?> clazz,
Object obj,
String fieldName,
Object value) |
static void |
setFinalField(Object obj,
String fieldName,
Object value) |
public static void setField(Object obj, String fieldName, Object value) throws NoSuchFieldException, IllegalArgumentException
public static void setFinalField(Object obj, String fieldName, Object value) throws NoSuchFieldException
NoSuchFieldException
public static void setFinalField(Class<?> clazz, Object obj, String fieldName, Object value) throws NoSuchFieldException
NoSuchFieldException
public static Object getField(Object obj, String fieldName) throws NoSuchFieldException, IllegalArgumentException
public static Object getField(Class<?> clazz, Object obj, String fieldName) throws NoSuchFieldException, IllegalArgumentException
public static Object invokeMethod(Class<?> clazz, Object obj, String methodName, Object... args) throws NoSuchMethodException, IllegalArgumentException, InvocationTargetException, IllegalAccessException
public static Object invokeMethod(Object obj, String methodName, Object... args) throws NoSuchMethodException, IllegalArgumentException, InvocationTargetException, IllegalAccessException
public static Map<String,Object> extractVariables(Object e)
e
- public static Map<String,Object> extractVariablesWithEnumAsString(Object e)
public static List<Field> getAllFields(List<Field> fields, Class<?> c)
fields
- c
- public static List<Method> getAllPublicMethods(List<Method> methods, Class<?> c)
public static List<String> getAllClasses(ClassLoader cl, String packageName)
public static Object constructNew(Class<?> clazz, Object... args) throws NoSuchMethodException, InstantiationException, IllegalArgumentException, IllegalAccessException