Package org.fest.reflect.field
Class Invoker<T>
java.lang.Object
org.fest.reflect.field.Invoker<T>
- Type Parameters:
T
- the declared type for the field to access.
Understands the use of reflection to access a field from an object.
The following is an example of proper usage of this class:
// Retrieves the value of the field "name" String name =field
("name").ofType
(String.class).in
(person).get
(); // Sets the value of the field "name" to "Yoda"field
("name").ofType
(String.class).in
(person).set
("Yoda"); // Retrieves the value of the static field "count" int count =staticField
("count").ofType
(int.class).in
(Person.class).get
(); // Sets the value of the static field "count" to 3field
("count").ofType
(int.class).in
(Person.class).set
(3);
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> Invoker<T>
createInvoker
(String fieldName, Class<?> expectedType, Object target) private static Field
get()
Returns the value of the field managed by this class.private static ReflectionError
incorrectFieldType
(Field field, Class<?> actual, Class<?> expected) info()
Returns the "real" field managed by this class.private static Field
lookupInClassHierarchy
(String fieldName, Class<?> declaringType) (package private) static <T> Invoker<T>
newInvoker
(String fieldName, Class<T> expectedType, Object target) (package private) static <T> Invoker<T>
newInvoker
(String fieldName, TypeRef<T> expectedType, Object target) void
Sets a value in the field managed by this class.private static Class<?>
private static void
verifyCorrectType
(Field field, Class<?> expectedType)
-
Field Details
-
target
-
field
-
accessible
private final boolean accessible
-
-
Constructor Details
-
Invoker
-
-
Method Details
-
newInvoker
-
newInvoker
-
createInvoker
-
typeOf
-
lookupInClassHierarchy
-
verifyCorrectType
-
field
-
incorrectFieldType
-
set
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
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.
-
info
Returns the "real" field managed by this class.- Returns:
- the "real" field managed by this class.
-