public final class ReflectionUtil extends Object
Modifier and Type | Method and Description |
---|---|
static <T> T |
createInstance(Class<T> clazz,
Object... parameter) |
static Class<?> |
forName(String className)
Returns the
Class object associated with the class or
interface with the given string name. |
static Map<Class<? extends Annotation>,List<Field>> |
getAllAnnotatedFields(Class<?> clazz) |
static List<Field> |
getAllFields(Class<?> clazz) |
static List<Field> |
getAllFieldsAssignableFrom(Class<?> assignableType,
Class<?> clazz) |
static List<Field> |
getAllFieldsAssinableFrom(Class<?> assinableType,
Class<?> clazz)
Deprecated.
typo
|
static List<Field> |
getAllFieldsWithAnnotation(Class<?> clazz,
Class<? extends Annotation> annotation) |
static List<Field> |
getAllFieldsWithAnnotation(Object instance,
Class<? extends Annotation> annotation) |
static List<Field> |
getAllFieldsWithSupportedAnnotation(Class<?> clazz,
IsSupportedAnnotationPredicate isSupportedAnnotationPredicate) |
static List<Method> |
getAllMethodsWithAnnotation(Class<?> clazz,
Class<? extends Annotation> annotation) |
static Set<Class<?>> |
getClasses(String... classNames) |
static Field |
getField(Class<?> clazz,
String fieldName) |
static Object |
getFieldValue(Object object,
Class<?> clazz,
String fieldName)
Get the value of a given field on a given object via reflection.
|
static Object |
getFieldValue(Object object,
Field field)
Get the value of a given field on a given object via reflection.
|
static Object |
getFieldValue(Object object,
String fieldName)
Get the value of a given field on a given object via reflection.
|
static Method |
getMethod(Class<?> clazz,
String methodName,
Class<?>... parameterTypes) |
static List<Method> |
getMethods(Class<?> clazz) |
static Object |
invokeMethod(Method method,
Object instance,
Object... arguments) |
static Object |
invokeMethod(Object object,
Class<?> clazz,
String methodName,
Object... arguments)
Invoke a given method with given arguments on a given object via
reflection.
|
static Object |
invokeMethod(Object object,
String methodName,
Object... arguments)
Invoke a given method with given arguments on a given object via
reflection.
|
static <T> Class<T> |
lookupClass(Class<T> type,
String className) |
static void |
setField(Field field,
Object target,
Object value) |
static void |
setField(String fieldName,
Object target,
Object value) |
static void |
setFieldValue(Object object,
Class<?> clazz,
String fieldName,
Object value)
Changing the value of a given field.
|
static void |
setFieldValue(Object object,
String fieldName,
Object value)
Changing the value of a given field.
|
public static List<Field> getAllFieldsWithSupportedAnnotation(Class<?> clazz, IsSupportedAnnotationPredicate isSupportedAnnotationPredicate)
public static List<Field> getAllFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation)
public static List<Method> getAllMethodsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation)
public static Map<Class<? extends Annotation>,List<Field>> getAllAnnotatedFields(Class<?> clazz)
public static List<Field> getAllFieldsAssignableFrom(Class<?> assignableType, Class<?> clazz)
@Deprecated public static List<Field> getAllFieldsAssinableFrom(Class<?> assinableType, Class<?> clazz)
public static List<Field> getAllFieldsWithAnnotation(Object instance, Class<? extends Annotation> annotation)
public static List<Method> getMethods(Class<?> clazz)
clazz
- objectClass.getMethods()
public static void setFieldValue(Object object, Class<?> clazz, String fieldName, Object value) throws NoSuchFieldException
object
- -- target object of injectionclazz
- -- type of argument objectfieldName
- -- name of field whose value is to be setvalue
- -- object that is injectedNoSuchFieldException
public static void setFieldValue(Object object, String fieldName, Object value)
object
- -- target object of injectionfieldName
- -- name of field whose value is to be setvalue
- -- object that is injectedpublic static Object getFieldValue(Object object, Class<?> clazz, String fieldName)
object
- -- target object of field accessclazz
- -- type of argument objectfieldName
- -- name of the fieldpublic static Object getFieldValue(Object object, Field field)
object
- -- target object of field accessfield
- -- target fieldpublic static Object getFieldValue(Object object, String fieldName)
object
- -- target object of field accessfieldName
- -- name of the fieldpublic static Object invokeMethod(Object object, Class<?> clazz, String methodName, Object... arguments) throws Exception
object
- -- target object of invocationclazz
- -- type of argument objectmethodName
- -- name of method to be invokedarguments
- -- arguments for method invocationException
- - operation exceptionpublic static Object invokeMethod(Method method, Object instance, Object... arguments) throws Exception
Exception
public static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException
NoSuchMethodException
public static Object invokeMethod(Object object, String methodName, Object... arguments) throws Exception
object
- -- target object of invocationmethodName
- -- name of method to be invokedarguments
- -- arguments for method invocationException
public static Class<?> forName(String className)
Class
object associated with the class or
interface with the given string name.className
- the fully qualified name of the desired class.Class
or nullpublic static void setField(Field field, Object target, Object value) throws Exception
Exception
public static void setField(String fieldName, Object target, Object value) throws Exception
Exception
public static <T> T createInstance(Class<T> clazz, Object... parameter) throws Exception
Exception
public static <T> Class<T> lookupClass(Class<T> type, String className) throws ClassNotFoundException
type
- - base classclassName
- - fully qualified class nameClassNotFoundException
Copyright © 2014. All rights reserved.