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()
FieldUtils instances should NOT be constructed in standard programming.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.reflect.Field |
getDeclaredField(java.lang.Class cls,
java.lang.String fieldName)
Gets an accessible
Field by name respecting scope. |
static java.lang.reflect.Field |
getDeclaredField(java.lang.Class cls,
java.lang.String fieldName,
boolean forceAccess)
Gets an accessible
Field by name breaking scope
if requested. |
static java.lang.reflect.Field |
getField(java.lang.Class cls,
java.lang.String fieldName)
Gets an accessible
Field by name respecting scope. |
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. |
static java.lang.Object |
readDeclaredField(java.lang.Object target,
java.lang.String fieldName)
Read the named public field.
|
static java.lang.Object |
readDeclaredField(java.lang.Object target,
java.lang.String fieldName,
boolean forceAccess)
Gets a Field value by name. |
static java.lang.Object |
readDeclaredStaticField(java.lang.Class cls,
java.lang.String fieldName)
Gets a static Field value by name.
|
static java.lang.Object |
readDeclaredStaticField(java.lang.Class cls,
java.lang.String fieldName,
boolean forceAccess)
Gets a static Field value by name.
|
static java.lang.Object |
readField(java.lang.reflect.Field field,
java.lang.Object target)
Read an accessible Field.
|
static java.lang.Object |
readField(java.lang.reflect.Field field,
java.lang.Object target,
boolean forceAccess)
Read a Field.
|
static java.lang.Object |
readField(java.lang.Object target,
java.lang.String fieldName)
Read the named public field.
|
static java.lang.Object |
readField(java.lang.Object target,
java.lang.String fieldName,
boolean forceAccess)
Read the named field.
|
static java.lang.Object |
readStaticField(java.lang.Class cls,
java.lang.String fieldName)
Read the named public static field.
|
static java.lang.Object |
readStaticField(java.lang.Class cls,
java.lang.String fieldName,
boolean forceAccess)
Read the named static field.
|
static java.lang.Object |
readStaticField(java.lang.reflect.Field field)
Read an accessible static Field.
|
static java.lang.Object |
readStaticField(java.lang.reflect.Field field,
boolean forceAccess)
Read a static Field.
|
static void |
writeDeclaredField(java.lang.Object target,
java.lang.String fieldName,
java.lang.Object value)
Write a public field.
|
static void |
writeDeclaredField(java.lang.Object target,
java.lang.String fieldName,
java.lang.Object value,
boolean forceAccess)
Write a public field.
|
static void |
writeDeclaredStaticField(java.lang.Class cls,
java.lang.String fieldName,
java.lang.Object value)
Write a named public static Field.
|
static void |
writeDeclaredStaticField(java.lang.Class cls,
java.lang.String fieldName,
java.lang.Object value,
boolean forceAccess)
Write a named static Field.
|
static void |
writeField(java.lang.reflect.Field field,
java.lang.Object target,
java.lang.Object value)
Write an accessible field.
|
static void |
writeField(java.lang.reflect.Field field,
java.lang.Object target,
java.lang.Object value,
boolean forceAccess)
Write a field.
|
static void |
writeField(java.lang.Object target,
java.lang.String fieldName,
java.lang.Object value)
Write a public field.
|
static void |
writeField(java.lang.Object target,
java.lang.String fieldName,
java.lang.Object value,
boolean forceAccess)
Write a field.
|
static void |
writeStaticField(java.lang.Class cls,
java.lang.String fieldName,
java.lang.Object value)
Write a named public static Field.
|
static void |
writeStaticField(java.lang.Class cls,
java.lang.String fieldName,
java.lang.Object value,
boolean forceAccess)
Write a named static Field.
|
static void |
writeStaticField(java.lang.reflect.Field field,
java.lang.Object value)
Write a public static Field.
|
static void |
writeStaticField(java.lang.reflect.Field field,
java.lang.Object value,
boolean forceAccess)
Write a static Field.
|
public FieldUtils()
This constructor is public to permit tools that require a JavaBean instance to operate.
public static java.lang.reflect.Field getField(java.lang.Class cls, java.lang.String fieldName)
Field
by name respecting scope.
Superclasses/interfaces will be considered.cls
- the class to reflect, must not be nullfieldName
- the field name to obtainjava.lang.IllegalArgumentException
- if the class or field name is nullpublic static java.lang.reflect.Field getField(java.lang.Class cls, java.lang.String fieldName, boolean forceAccess)
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 nullpublic static java.lang.reflect.Field getDeclaredField(java.lang.Class cls, java.lang.String fieldName)
Field
by name respecting scope.
Only the specified class will be considered.cls
- the class to reflect, must not be nullfieldName
- the field name to obtainjava.lang.IllegalArgumentException
- if the class or field name is nullpublic static java.lang.reflect.Field getDeclaredField(java.lang.Class cls, java.lang.String fieldName, boolean forceAccess)
Field
by name breaking scope
if requested. Only the specified class 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 nullpublic static java.lang.Object readStaticField(java.lang.reflect.Field field) throws java.lang.IllegalAccessException
field
- to readjava.lang.IllegalArgumentException
- if the field is null or not staticjava.lang.IllegalAccessException
- if the field is not accessiblepublic static java.lang.Object readStaticField(java.lang.reflect.Field field, boolean forceAccess) throws java.lang.IllegalAccessException
field
- to readforceAccess
- whether to break scope restrictions using the
setAccessible
method.java.lang.IllegalArgumentException
- if the field is null or not staticjava.lang.IllegalAccessException
- if the field is not made accessiblepublic static java.lang.Object readStaticField(java.lang.Class cls, java.lang.String fieldName) throws java.lang.IllegalAccessException
cls
- the class to reflect, must not be nullfieldName
- the field name to obtainjava.lang.IllegalArgumentException
- if the class or field name is nulljava.lang.IllegalAccessException
- if the field is not accessiblepublic static java.lang.Object readStaticField(java.lang.Class cls, java.lang.String fieldName, boolean forceAccess) throws java.lang.IllegalAccessException
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 the field is not made accessiblepublic static java.lang.Object readDeclaredStaticField(java.lang.Class cls, java.lang.String fieldName) throws java.lang.IllegalAccessException
cls
- the class to reflect, must not be nullfieldName
- the field name to obtainjava.lang.IllegalArgumentException
- if the class or field name is nulljava.lang.IllegalAccessException
- if the field is not accessiblepublic static java.lang.Object readDeclaredStaticField(java.lang.Class cls, java.lang.String fieldName, boolean forceAccess) throws java.lang.IllegalAccessException
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 the field is not made accessiblepublic 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 accessiblepublic 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 accessiblepublic static java.lang.Object readField(java.lang.Object target, java.lang.String fieldName) throws java.lang.IllegalAccessException
target
- the object to reflect, must not be nullfieldName
- the field name to obtainjava.lang.IllegalArgumentException
- if the class or field name is nulljava.lang.IllegalAccessException
- if the named field is not publicpublic static 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 accessiblepublic static java.lang.Object readDeclaredField(java.lang.Object target, java.lang.String fieldName) throws java.lang.IllegalAccessException
target
- the object to reflect, must not be nullfieldName
- the field name to obtainjava.lang.IllegalArgumentException
- if the class or field name is nulljava.lang.IllegalAccessException
- if the named field is not publicpublic static java.lang.Object readDeclaredField(java.lang.Object target, java.lang.String fieldName, boolean forceAccess) throws java.lang.IllegalAccessException
Gets a Field value by name. Only the class of the specified object will be considered.
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 target
or fieldName
is nulljava.lang.IllegalAccessException
- if the field is not made accessiblepublic static void writeStaticField(java.lang.reflect.Field field, java.lang.Object value) throws java.lang.IllegalAccessException
field
- to writevalue
- to setjava.lang.IllegalArgumentException
- if the field is null or not staticjava.lang.IllegalAccessException
- if the field is not public or is finalpublic static void writeStaticField(java.lang.reflect.Field field, java.lang.Object value, boolean forceAccess) throws java.lang.IllegalAccessException
field
- to writevalue
- to setforceAccess
- whether to break scope restrictions using the
setAccessible
method. False
will only
match public fields.java.lang.IllegalArgumentException
- if the field is null or not staticjava.lang.IllegalAccessException
- if the field is not made accessible or is finalpublic static void writeStaticField(java.lang.Class cls, java.lang.String fieldName, java.lang.Object value) throws java.lang.IllegalAccessException
cls
- Class on which the Field is to be foundfieldName
- to writevalue
- to setjava.lang.IllegalArgumentException
- if the field cannot be located or is not staticjava.lang.IllegalAccessException
- if the field is not public or is finalpublic static void writeStaticField(java.lang.Class cls, java.lang.String fieldName, java.lang.Object value, boolean forceAccess) throws java.lang.IllegalAccessException
cls
- Class on which the Field is to be foundfieldName
- to writevalue
- to setforceAccess
- whether to break scope restrictions using the
setAccessible
method. False
will only
match public fields.java.lang.IllegalArgumentException
- if the field cannot be located or is not staticjava.lang.IllegalAccessException
- if the field is not made accessible or is finalpublic static void writeDeclaredStaticField(java.lang.Class cls, java.lang.String fieldName, java.lang.Object value) throws java.lang.IllegalAccessException
cls
- Class on which the Field is to be foundfieldName
- to writevalue
- to setjava.lang.IllegalArgumentException
- if the field cannot be located or is not staticjava.lang.IllegalAccessException
- if the field is not public or is finalpublic static void writeDeclaredStaticField(java.lang.Class cls, java.lang.String fieldName, java.lang.Object value, boolean forceAccess) throws java.lang.IllegalAccessException
cls
- Class on which the Field is to be foundfieldName
- to writevalue
- to setforceAccess
- whether to break scope restrictions using the
setAccessible
method. False
will only
match public fields.java.lang.IllegalArgumentException
- if the field cannot be located or is not staticjava.lang.IllegalAccessException
- if the field is not made accessible or is finalpublic static void writeField(java.lang.reflect.Field field, java.lang.Object target, java.lang.Object value) throws java.lang.IllegalAccessException
field
- to writetarget
- the object to call on, may be null for static fieldsvalue
- to setjava.lang.IllegalArgumentException
- if the field is nulljava.lang.IllegalAccessException
- if the field is not accessible or is finalpublic static void writeField(java.lang.reflect.Field field, java.lang.Object target, java.lang.Object value, boolean forceAccess) throws java.lang.IllegalAccessException
field
- to writetarget
- the object to call on, may be null for static fieldsvalue
- to setforceAccess
- whether to break scope restrictions using the
setAccessible
method. False
will only
match public fields.java.lang.IllegalArgumentException
- if the field is nulljava.lang.IllegalAccessException
- if the field is not made accessible or is finalpublic static void writeField(java.lang.Object target, java.lang.String fieldName, java.lang.Object value) throws java.lang.IllegalAccessException
target
- the object to reflect, must not be nullfieldName
- the field name to obtainvalue
- to setjava.lang.IllegalArgumentException
- if target
or fieldName
is nulljava.lang.IllegalAccessException
- if the field is not accessiblepublic static void writeField(java.lang.Object target, java.lang.String fieldName, java.lang.Object value, boolean forceAccess) throws java.lang.IllegalAccessException
target
- the object to reflect, must not be nullfieldName
- the field name to obtainvalue
- to setforceAccess
- whether to break scope restrictions using the
setAccessible
method. False
will only
match public fields.java.lang.IllegalArgumentException
- if target
or fieldName
is nulljava.lang.IllegalAccessException
- if the field is not made accessiblepublic static void writeDeclaredField(java.lang.Object target, java.lang.String fieldName, java.lang.Object value) throws java.lang.IllegalAccessException
target
- the object to reflect, must not be nullfieldName
- the field name to obtainvalue
- to setjava.lang.IllegalArgumentException
- if target
or fieldName
is nulljava.lang.IllegalAccessException
- if the field is not made accessiblepublic static void writeDeclaredField(java.lang.Object target, java.lang.String fieldName, java.lang.Object value, boolean forceAccess) throws java.lang.IllegalAccessException
target
- the object to reflect, must not be nullfieldName
- the field name to obtainvalue
- to setforceAccess
- whether to break scope restrictions using the
setAccessible
method. False
will only
match public fields.java.lang.IllegalArgumentException
- if target
or fieldName
is nulljava.lang.IllegalAccessException
- if the field is not made accessibleCopyright © 2010 - 2020 Adobe. All Rights Reserved