public class Reflection extends Object
| Modifier and Type | Field and Description |
|---|---|
static Object |
INVOCATION_ERROR
This object is returned by
invokeMethod(..) when an error occurs.
|
| Constructor and Description |
|---|
Reflection()
|
| Modifier and Type | Method and Description |
|---|---|
protected static <T> T |
construct(Class
This constructs an instance of t if a constructor is found that matches the arguments provided.
|
static Object |
getFieldValue(String
Uses reflection to retrieve a static field from a class.
|
static Object |
invokeMethod(Class
This uses reflection to call a method that may not exist in the compiling JVM.
|
static String |
nameStaticField(Class
This debugging tool combs through a class and tells you what public static field has the value you've provided.
|
static Object |
parse(String
Parse an object as null, an int, a long, a float, a String, a static field, or "new xyz(..)" (where ".." looks recursively for a comma-separated list of arguments)).
|
protected static Object |
parseCommaSeparatedList(String
Return an array of objects based on a comma-separated description of its contents.
|
public static final ObjectINVOCATION_ERROR
invokeMethod(..) when an error occurs.
public static ObjectgetFieldValue(String className, String fieldName)
protected static Object[] parseCommaSeparatedList(String arguments)
public static Objectparse(String input)
For example, you can call: parse( "new Color( 255, 0, 128 )" ); parse( "new com.bric.swing.resources.ArrowIcon( javax.swing.SwingConstants.EAST, 24, 24 )" ); parse( "new com.bric.swing.resources.TriangleIcon( javax.swing.SwingConstants.EAST, 24, 24, new Color(0)" );
The class name/constants must be fully qualified.
protected static <T> T construct(Class<T> t, String arguments)
t - the type of class to construct.
arguments - a comma separated list of simple arguments, such as primitives, strings, or static fields.
public static ObjectinvokeMethod(Class <?> c, Object obj, String methodName, Object [] arguments)
public static StringnameStaticField(Class <?> c, Object value)
For example, you can call: nameStaticField(BufferedImage.class,new Integer(BufferedImage.TYPE_INT_ARGB))
And this method will return "TYPE_INT_ARGB".
c - the class of interest
value - the value. Primitives must be wrapped.
null if not hits were found. (Or if multiple hits were found, this returns a list of possible matches.)