public final class ReflectionUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static Object |
call(Object bean,
Method method,
Object... args)
Make reflective method calls without having to handle two checked exceptions (IllegalAccessException and
InvocationTargetException).
|
static Object |
call(Object bean,
String methodName,
Object... args)
Make a reflective method call in one step.
|
static <T extends Annotation> |
getClassAnnotation(Class<?> classToCheck,
Class<T> annoClass)
Determine if the passed in class (classToCheck) has the annotation (annoClass) on itself,
any of its super classes, any of it's interfaces, or any of it's super interfaces.
|
static String |
getClassName(Object o)
Return the name of the class on the object, or "null" if the object is null.
|
static String |
getClassNameFromByteCode(byte[] byteCode)
Given a byte[] of a Java .class file (compiled Java), this code will retrieve the class name from those bytes.
|
static Constructor<?> |
getConstructor(Class<?> clazz,
Class<?>... parameterTypes) |
static List<Field> |
getDeclaredFields(Class<?> c)
Retrieve the declared fields on a Class.
|
static void |
getDeclaredFields(Class<?> c,
Collection<Field> fields)
Get all non static, non transient, fields of the passed in class, including
private fields.
|
static Map<String,Field> |
getDeepDeclaredFieldMap(Class<?> c)
Return all Fields from a class (including inherited), mapped by
String field name to java.lang.reflect.Field.
|
static Collection<Field> |
getDeepDeclaredFields(Class<?> c)
Get all non static, non transient, fields of the passed in class, including
private fields.
|
static Method |
getMethod(Class<?> c,
String methodName,
Class<?>... types)
Fetch a public method reflectively by name with argument types.
|
static Method |
getMethod(Object bean,
String methodName,
int argCount)
Fetch the named method from the passed in Object instance.
|
static <T extends Annotation> |
getMethodAnnotation(Method method,
Class<T> annoClass) |
static Method |
getNonOverloadedMethod(Class<?> clazz,
String methodName)
Fetch the named method from the passed in Class.
|
public static <T extends Annotation> T getClassAnnotation(Class<?> classToCheck, Class<T> annoClass)
public static <T extends Annotation> T getMethodAnnotation(Method method, Class<T> annoClass)
public static Method getMethod(Class<?> c, String methodName, Class<?>... types)
c - Class on which method is to be found.methodName - String name of method to find.types - Argument types for the method (null is used for no argument methods).public static List<Field> getDeclaredFields(Class<?> c)
public static Collection<Field> getDeepDeclaredFields(Class<?> c)
c - Class instancepublic static void getDeclaredFields(Class<?> c, Collection<Field> fields)
c - Class instance
that would need further processing (reference fields). This
makes field traversal on a class faster as it does not need to
continually process known fields like primitives.public static Map<String,Field> getDeepDeclaredFieldMap(Class<?> c)
c - Class whose fields are being fetched.public static Object call(Object bean, Method method, Object... args)
bean - Object (instance) on which to call method.method - Method instance from target object [easily obtained by calling ReflectionUtils.getMethod()].args - Arguments to pass to method.public static Object call(Object bean, String methodName, Object... args)
bean - Object instance on which to call method.methodName - String name of method to call.args - Arguments to pass.public static Method getMethod(Object bean, String methodName, int argCount)
bean - Object on which the named method will be found.methodName - String name of method to be located on the controller.argCount - int number of arguments. This is used as part of the cache key to allow for
duplicate method names as long as the argument list length is different.IllegalArgumentExceptionpublic static Constructor<?> getConstructor(Class<?> clazz, Class<?>... parameterTypes)
public static Method getNonOverloadedMethod(Class<?> clazz, String methodName)
clazz - Class that contains the desired method.methodName - String name of method to be located on the controller.IllegalArgumentExceptionpublic static String getClassName(Object o)
o - Object to get the class name.public static String getClassNameFromByteCode(byte[] byteCode) throws Exception
byteCode - byte[] of compiled byte code.Exception - potential io exceptions can happenCopyright © 2024. All rights reserved.