public class ReflectionUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T extends Annotation> |
getAnnotation(Class<T> annotationType,
AnnotatedElement element)
Gets the provided annotation from the provided annotated element, if it exists.
|
static List<Field> |
getDeclaredFields(Class clazz)
Returns the result of running
Class.getDeclaredFields() on the
supplied class, as well as all its super types. |
static Object |
getFieldValue(Field field,
Object object)
Gets the value of the
field for the given object. |
static void |
setFieldValue(Field field,
Object object,
Object value)
Sets the value of the
field for the given object. |
public static Object getFieldValue(Field field, Object object)
field for the given object. It will change the accessibility of the field if necessary.
Setting it back to its original value at the end of the method call.field - the field to read fromobject - the object to read the field frompublic static void setFieldValue(Field field, Object object, Object value)
field for the given object. It will change the accessibility of the field if necessary.
Setting it back to its original value at the end of the method call.field - the field to set the value ofobject - the object to for which to set the field value.value - the new value to be set to the field of object.public static List<Field> getDeclaredFields(Class clazz)
Class.getDeclaredFields() on the
supplied class, as well as all its super types. Fields are ordered in
ascending hierarchy order (subclasses first).clazz - public static <T extends Annotation> T getAnnotation(@Nonnull Class<T> annotationType, @Nullable AnnotatedElement element)
Will only return a result if the found annotation is from the same class loader as the target type.
Will emit a warning into the log if the annotation is found but has been loaded from a different class loader.
annotationType - The annotation to search forelement - The element to searchnullCopyright © 2016 Atlassian. All rights reserved.