r01f.reflection.fluent
Class FieldInvoker<T>
java.lang.Object
r01f.reflection.fluent.FieldInvoker<T>
- Type Parameters:
T - the declared type for the field to access.
Usage example:
// Retrieves the value of the field "name"
String name = Reflection.field("name").ofType(String.class).in(person).get();
// Sets the value of the field "name" to "Yoda"
Reflection.field("name").ofType(String.class).in(person).set("Yoda");
// Retrieves the value of the static field "count"
int count = Reflection.staticField("count").ofType(int.class).in(Person.class).get();
// Sets the value of the static field "count" to 3
Reflection.staticField("count").ofType(int.class).in(Person.class).set(3);
public final class FieldInvoker<T>
- extends java.lang.Object
Object's field access using reflection
|
Constructor Summary |
private |
FieldInvoker(java.lang.Object target,
java.lang.reflect.Field field)
|
|
Method Summary |
private static
|
_createInvoker(java.lang.String fieldName,
java.lang.Class<?> expectedType,
java.lang.Object target)
|
private static java.lang.reflect.Field |
_field(java.lang.String fieldName,
java.lang.Class<?> declaringType)
|
private static ReflectionException |
_incorrectFieldType(java.lang.reflect.Field field,
java.lang.Class<?> actual,
java.lang.Class<?> expected)
|
private static java.lang.reflect.Field |
_lookupInClassHierarchy(java.lang.String fieldName,
java.lang.Class<?> declaringType)
|
private static void |
_makeAccessible(java.lang.reflect.Field field)
|
private static java.lang.Class<?> |
_typeOf(java.lang.Object target)
|
private static void |
_verifyCorrectType(java.lang.reflect.Field field,
java.lang.Class<?> expectedType)
|
T |
get()
Returns the value of the field managed by this class. |
java.lang.reflect.Field |
getField()
Returns the "real" field managed by this class. |
(package private) static
|
newInvoker(java.lang.String fieldName,
java.lang.Class<T> expectedType,
java.lang.Object target)
|
(package private) static
|
newInvoker(java.lang.String fieldName,
TypeRef<T> expectedType,
java.lang.Object target)
|
void |
set(T value)
Sets a value in the field managed by this class. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_targetObj
private final java.lang.Object _targetObj
_field
private final java.lang.reflect.Field _field
_accessible
private final boolean _accessible
FieldInvoker
private FieldInvoker(java.lang.Object target,
java.lang.reflect.Field field)
newInvoker
static <T> FieldInvoker<T> newInvoker(java.lang.String fieldName,
java.lang.Class<T> expectedType,
java.lang.Object target)
newInvoker
static <T> FieldInvoker<T> newInvoker(java.lang.String fieldName,
TypeRef<T> expectedType,
java.lang.Object target)
set
public void set(T value)
- Sets a value in the field managed by this class.
- Parameters:
value - the value to set.
- Throws:
ReflectionError - if the given value cannot be set.
get
public T get()
- Returns the value of the field managed by this class.
- Returns:
- the value of the field managed by this class.
- Throws:
ReflectionError - if the value of the field cannot be retrieved.
getField
public java.lang.reflect.Field getField()
- Returns the "real" field managed by this class.
- Returns:
- the "real" field managed by this class.
_createInvoker
private static <T> FieldInvoker<T> _createInvoker(java.lang.String fieldName,
java.lang.Class<?> expectedType,
java.lang.Object target)
_typeOf
private static java.lang.Class<?> _typeOf(java.lang.Object target)
_lookupInClassHierarchy
private static java.lang.reflect.Field _lookupInClassHierarchy(java.lang.String fieldName,
java.lang.Class<?> declaringType)
_makeAccessible
private static void _makeAccessible(java.lang.reflect.Field field)
_verifyCorrectType
private static void _verifyCorrectType(java.lang.reflect.Field field,
java.lang.Class<?> expectedType)
_field
private static java.lang.reflect.Field _field(java.lang.String fieldName,
java.lang.Class<?> declaringType)
_incorrectFieldType
private static ReflectionException _incorrectFieldType(java.lang.reflect.Field field,
java.lang.Class<?> actual,
java.lang.Class<?> expected)