|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||

java.lang.Objectpatterntesting.runtime.util.ReflectionHelper
public class ReflectionHelper
This class is a helper class to access some fields via reflection. Normally you should avoid reflection. Handle with care if you use it.
| Method Summary | |
|---|---|
static Field |
getField(Class<?> cl,
String name)
Tries to get the wanted field. |
static Object |
getFieldValue(Object obj,
String name)
If it can it returns the value of the given field. |
static Method |
getMethod(Class<?> cl,
String name,
Class<?>... parameterTypes)
Gets the method. |
static Method |
getMethod(Class<?> cl,
String name,
Object... args)
Gets the method. |
static Collection<Field> |
getUninitializedNonStaticFields(Object obj)
To get all uninitialized field you can call this method. |
static Object |
invokeMethod(Object target,
String name,
Object... args)
Invoke method. |
static boolean |
isStatic(Field field)
Checks if the given field is static. |
static String |
toShortString(Collection<Field> fields)
To short string. |
static String |
toShortString(Field field)
To short string. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static Field getField(Class<?> cl,
String name)
throws NoSuchFieldException
cl - the clname - the name
NoSuchFieldException - the no such field exception
public static Object getFieldValue(Object obj,
String name)
throws NoSuchFieldException,
IllegalArgumentException,
IllegalAccessException
obj - the objname - the name
NoSuchFieldException - the no such field exception
IllegalArgumentException - the illegal argument exception
IllegalAccessException - the illegal access exceptionpublic static Collection<Field> getUninitializedNonStaticFields(Object obj)
obj - the object where to get the fields from
public static boolean isStatic(Field field)
field - the field
public static String toShortString(Field field)
field - the field
public static String toShortString(Collection<Field> fields)
fields - the fields
public static Method getMethod(Class<?> cl,
String name,
Object... args)
throws NoSuchMethodException
cl - the clname - the nameargs - the args
NoSuchMethodException - the no such method exception
public static Method getMethod(Class<?> cl,
String name,
Class<?>... parameterTypes)
throws NoSuchMethodException
cl - e.g. class java.lang.ClassLoadername - e.g. "getPackages"parameterTypes - the parameter types
NoSuchMethodException - the no such method exception
public static Object invokeMethod(Object target,
String name,
Object... args)
target - the targetname - the method nameargs - the args for the method
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||