r01f.reflection.fluent
Class StaticFieldReflection

java.lang.Object
  extended by r01f.reflection.fluent.StaticFieldReflection

public final class StaticFieldReflection
extends java.lang.Object

Static field reflection Usage example:

   // 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);
 
   // Retrieves the value of the static field "commonPowers"
   List commmonPowers = Reflection.staticField("commonPowers").ofType(new TypeRef>() {}).in(Jedi.class).get();
 
   // Sets the value of the static field "commonPowers"
   List commonPowers = new ArrayList();
   commonPowers.add("jump");
   Reflection.staticField("commonPowers").ofType(new TypeRef>() {}).in(Jedi.class).set(commonPowers);
 


Field Summary
private  java.lang.String _fieldName
           
 
Constructor Summary
private StaticFieldReflection(java.lang.String fieldName)
           
 
Method Summary
private static void _validateIsNotNullOrEmpty(java.lang.String fieldName)
           
<T> StaticFieldTypes.StaticFieldType<T>
ofType(java.lang.Class<T> type)
          Sets the type of the field to access.
<T> StaticFieldTypes.StaticFieldTypeGenerics<T>
ofType(TypeRef<T> type)
          Sets the type reference of the field to access.
(package private) static StaticFieldReflection startStaticFieldAccess(java.lang.String fieldName)
          Creates a new StaticFieldReflection: the starting point of the fluent interface for accessing static fields using Java Reflection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_fieldName

private final java.lang.String _fieldName
Constructor Detail

StaticFieldReflection

private StaticFieldReflection(java.lang.String fieldName)
Method Detail

startStaticFieldAccess

static StaticFieldReflection startStaticFieldAccess(java.lang.String fieldName)
Creates a new StaticFieldReflection: the starting point of the fluent interface for accessing static fields using Java Reflection.

Parameters:
fieldName - the name of the field to access using Java Reflection.
Returns:
the created StaticFieldName.
Throws:
java.lang.NullPointerException - if the given name is null.
java.lang.IllegalArgumentException - if the given name is empty.

ofType

public <T> StaticFieldTypes.StaticFieldType<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> StaticFieldTypes.StaticFieldTypeGenerics<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. Usage example:
   List commmonPowers = Reflection.staticField("commonPowers").ofType(new TypeRef>() {}).in(Jedi.class).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)