Fields by reflection. Adapted and refactored from the dormant [reflect] Commons
sandbox component.
The ability is provided to break the scoping restrictions coded by the programmer. This can allow fields to be changed that shouldn't be. This facility should be used with care.
| Access | Constructor and Description |
|---|---|
| public | FieldUtils()
Deprecated
TODO Make private in 4.0.
|
| Modifier and Type | Method and Description |
|---|---|
| public static Field[] | Returns: an array of Fields (possibly empty).the cls)Class to queryGets all fields of the given class and its parents (if any). |
| public static List | Returns: a list of Fields (possibly empty).the cls)Class to queryGets all fields of the given class and its parents (if any). |
| public static Field | Returns: the Field object.the cls, final String Class to reflect, must not be nullthe field name to obtain. fieldName)Gets an accessible |
| public static Field | Returns: the Field objectthe cls, final String Class to reflect, must not be null.the field name to obtain. fieldName, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method. false will only
match public fields.Gets an accessible |
| public static Field | |
| public static Field | Returns: the Field object.the cls, final String Class to reflect, must not be null.the field name to obtain. fieldName, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method. false will only
match public fields.Gets an accessible |
| public static List | Returns: a list of Fields (possibly empty).the cls, final Class<? extends Annotation> Class to query.the annotationCls)Annotation that must be present on a field to be matched.Gets all fields of the given class and its parents (if any) that are annotated with the given annotation. |
| public static Field[] | Returns: an array of Fields (possibly empty).the cls, final Class<? extends Annotation> Class to query.the annotationCls)Annotation that must be present on a field to be matchedGets all fields of the given class and its parents (if any) that are annotated with the given annotation. |
| public static Object | Returns: the value of the field.the object to reflect, must not be target, final String null.the field name to obtain. fieldName)Reads the named |
| public static Object | Returns: the Field object.the object to reflect, must not be target, final String null.the field name to obtain. fieldName, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method. false will only
match public fields.Gets a |
| public static Object | Returns: the value of the field.the cls, final String Class to reflect, must not be null.the field name to obtain. fieldName)Gets the value of a |
| public static Object | Returns: the Field objectthe cls, final String Class to reflect, must not be null.the field name to obtain. fieldName, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method. false will only
match public fields.Gets the value of a |
| public static Object | |
| public static Object | Returns: the field valuethe field to use. field, final Object the object to call on, may be target, final boolean null for static fields.whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method.Reads a |
| public static Object | |
| public static Object | Returns: the field valuethe object to reflect, must not be target, final String null.the field name to obtain. fieldName, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method. false will only
match public fields.Reads the named |
| public static Object | Returns: the value of the field.the cls, final String Class to reflect, must not be null.the field name to obtain. fieldName)Reads the named |
| public static Object | Returns: the Field object.the cls, final String Class to reflect, must not be null.the field name to obtain. fieldName, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method. false will only
match public fields.Reads the named |
| public static Object | Returns: the field value.to read. field)Reads an accessible |
| public static Object | Returns: the field value.to read. field, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method.Reads a static |
| public static void | removeFinalModifier(final Field
to remove the final modifier. field)Removes the final modifier from a |
| public static void | removeFinalModifier(final Field
to remove the final modifier. field, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method. false will only
match public fields.
Deprecated
As of Java 12, we can no longer drop the
final modifier, thus
rendering this method obsolete.
Removes the final modifier from a |
| pack-priv static Field | |
| public static void | writeDeclaredField(final Object
the object to reflect, must not be target, final String null.the field name to obtain. fieldName, final Object the new value. value)Writes a |
| public static void | writeDeclaredField(final Object
the object to reflect, must not be target, final String null.the field name to obtain. fieldName, final Object the new value. value, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method. false will only
match public fields.Writes a |
| public static void | |
| public static void | writeDeclaredStaticField(final Class<?>
Class on which the field is to be found.to write fieldName, final Object the new value. value, final boolean whether to break scope restrictions using the forceAccess)AccessibleObject#setAccessible(boolean) method.
false will only match public fields.Writes a named |
| public static void | writeField(final Field
to write. field, final Object the object to call on, may be target, final Object null for static fields.the new value. value)Writes an accessible |
| public static void | writeField(final Field
to write. field, final Object the object to call on, may be target, final Object null for static fieldsthe new value. value, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method. false will only
match public fields.Writes a |
| public static void | writeField(final Object
the object to reflect, must not be target, final String null.the field name to obtain. fieldName, final Object the new value. value)Writes a |
| public static void | writeField(final Object
the object to reflect, must not be target, final String null.the field name to obtain. fieldName, final Object the new value. value, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method. false will only
match public fields.Writes a |
| public static void | |
| public static void | writeStaticField(final Class<?>
Class on which the field is to be found.to write. fieldName, final Object the new value. value, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method. false will only
match public fields.Writes a named |
| public static void | writeStaticField(final Field
to write. field, final Object the new value. value)Writes a |
| public static void | writeStaticField(final Field
to write. field, final Object the new value. value, final boolean whether to break scope restrictions using the
forceAccess)AccessibleObject#setAccessible(boolean) method. false will only
match public fields.Writes a static |