public final class FieldUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
FieldUtil.FieldCallback
Callback interface invoked on each field in the hierarchy.
|
static interface |
FieldUtil.FieldFilter
Callback optionally used to filter fields to be operated on by a field callback.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
doWithFields(Class<?> clazz,
FieldUtil.FieldCallback fc,
FieldUtil.FieldFilter ff)
Invoke the given callback on all fields in the target class, going up the
class hierarchy to get all declared fields.
|
static <T> T |
getFieldValue(Field field,
Object object)
get Filed value or throw IllegalArgumentException for given field
|
static List<Field> |
getPropertyFields(Class<?> type) |
static boolean |
isRequiredField(Field field)
Return true if is Required Field else false
|
static void |
makeAccessible(Field field)
Make the given field accessible, explicitly setting it accessible if
necessary.
|
static void |
setFieldValue(Field field,
Object target,
Object value)
Set the field represented by the supplied
field object on the
specified target object to the specified value. |
public static List<Field> getPropertyFields(Class<?> type)
type - may not be nullpublic static boolean isRequiredField(Field field)
field - may not be nullpublic static <T> T getFieldValue(Field field, Object object)
T - required typefield - may not be nullobject - may not be nullpublic static void setFieldValue(Field field, Object target, Object value)
field object on the
specified target object to the specified value.
In accordance with Field.set(Object, Object) semantics, the new value
is automatically unwrapped if the underlying field has a primitive type.
Thrown exceptions are handled via a call to IllegalStateException.
field - the field to settarget - the target object on which to set the fieldvalue - the value to set (may be null)public static void doWithFields(Class<?> clazz, FieldUtil.FieldCallback fc, FieldUtil.FieldFilter ff)
clazz - the target class to analyzefc - the callback to invoke for each fieldff - the filter that determines the fields to apply the callback topublic static void makeAccessible(Field field)
setAccessible(true) method is only called
when actually necessary, to avoid unnecessary conflicts with a JVM
SecurityManager (if active).field - the field to make accessibleAccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[], boolean)Copyright © 2018 Mario Tema. All rights reserved.