r01f.reflection.fluent
Class FieldReflection
java.lang.Object
r01f.reflection.fluent.FieldReflection
public final class FieldReflection
- extends java.lang.Object
Reflection for a class Field
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 field "powers"
List powers = Reflection.field("powers").ofType(new TypeRef>() {}).in(jedi).get();
// Sets the value of the field "powers"
List powers = new ArrayList
powers.add("heal");
Reflection.field("powers").ofType(new TypeRef >() {}).in(jedi).set(powers);
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_fieldName
private final java.lang.String _fieldName
FieldReflection
private FieldReflection(java.lang.String fieldName)
startFieldAccess
static FieldReflection startFieldAccess(java.lang.String fieldName)
- Creates a new
FieldReflection: the starting point of the fluent interface for accessing fields using Java Reflection.
- Parameters:
fieldName - the name of the field to access using Java Reflection.
- Returns:
- the created
FieldName.
- Throws:
java.lang.NullPointerException - if the given name is null.
java.lang.IllegalArgumentException - if the given name is empty.
ofType
public <T> FieldTypes.FieldType<T> ofType(java.lang.Class<T> type)
- Sets the type of the field to access.
- Type Parameters:
T - the generic type of the field type.- Parameters:
type - the type of the field to access.
- Returns:
- a recipient for the field type.
- Throws:
java.lang.NullPointerException - if the given type is null.
ofType
public <T> FieldTypes.FieldTypeGenerics<T> ofType(TypeRef<T> type)
- Sets the type reference of the field to access.
This method reduces casting when the type of the field to access uses generics.
For example:
List powers = Reflection.field("powers").ofType(new TypeRef>() {}).in(jedi).get}();
- Type Parameters:
T - the generic type of the field type.- Parameters:
type - the type of the field to access.
- Returns:
- a recipient for the field type.
- Throws:
java.lang.NullPointerException - if the given type reference is null.
_validateIsNotNullOrEmpty
private static void _validateIsNotNullOrEmpty(java.lang.String fieldName)