public class FieldUtils
extends java.lang.Object
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.
Constructor and Description |
---|
FieldUtils() |
Modifier and Type | Method and Description |
---|---|
(package private) static java.lang.reflect.Field |
getField(java.lang.Class<?> cls,
java.lang.String fieldName,
boolean forceAccess)
Gets an accessible
Field by name breaking scope if requested. |
private static java.lang.Object |
readField(java.lang.reflect.Field field,
java.lang.Object target)
Reads an accessible Field.
|
private static java.lang.Object |
readField(java.lang.reflect.Field field,
java.lang.Object target,
boolean forceAccess)
Reads a Field.
|
(package private) static java.lang.Object |
readField(java.lang.Object target,
java.lang.String fieldName,
boolean forceAccess)
Reads the named field.
|
static java.lang.reflect.Field getField(java.lang.Class<?> cls, java.lang.String fieldName, boolean forceAccess) throws java.lang.IllegalAccessException
Field
by name breaking scope if requested. Superclasses/interfaces will be
considered.cls
- the class to reflect, must not be nullfieldName
- the field name to obtainforceAccess
- whether to break scope restrictions using the setAccessible
method.
False
will only match public fields.java.lang.IllegalArgumentException
- if the class or field name is nulljava.lang.IllegalAccessException
- if field exists but is not publicprivate static java.lang.Object readField(java.lang.reflect.Field field, java.lang.Object target) throws java.lang.IllegalAccessException
field
- the field to usetarget
- the object to call on, may be null for static fieldsjava.lang.IllegalArgumentException
- if the field is nulljava.lang.IllegalAccessException
- if the field is not accessibleprivate static java.lang.Object readField(java.lang.reflect.Field field, java.lang.Object target, boolean forceAccess) throws java.lang.IllegalAccessException
field
- the field to usetarget
- the object to call on, may be null for static fieldsforceAccess
- whether to break scope restrictions using the setAccessible
method.java.lang.IllegalArgumentException
- if the field is nulljava.lang.IllegalAccessException
- if the field is not made accessiblestatic java.lang.Object readField(java.lang.Object target, java.lang.String fieldName, boolean forceAccess) throws java.lang.IllegalAccessException
target
- the object to reflect, must not be nullfieldName
- the field name to obtainforceAccess
- whether to break scope restrictions using the setAccessible
method.
False
will only match public fields.java.lang.IllegalArgumentException
- if the class or field name is nulljava.lang.IllegalAccessException
- if the named field is not made accessible