Package org.fest.reflect.field
Class StaticFieldName
- java.lang.Object
-
- org.fest.reflect.field.StaticFieldName
-
public final class StaticFieldName extends java.lang.Object
Understands the name of a static field to access using Java Reflection.The following is an example of proper usage of this class:
// 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 3staticField
("count").ofType
(int.class).in
(Person.class).set
(3); // Retrieves the value of the static field "commonPowers" List<String> commmonPowers =staticField
("commonPowers").ofType
(newTypeRef
<List<String>>() {}).in
(Jedi.class).get
(); // Sets the value of the static field "commonPowers" List<String> commonPowers = new ArrayList<String>(); commonPowers.add("jump");staticField
("commonPowers").ofType
(newTypeRef
<List<String>>() {}).in
(Jedi.class).set
(commonPowers);- Author:
- Alex Ruiz
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StaticFieldName
beginStaticFieldAccess(java.lang.String name)
Creates a new
: the starting point of the fluent interface for accessing static fields using Java Reflection.StaticFieldName
<T> StaticFieldType<T>
ofType(java.lang.Class<T> type)
Sets the type of the field to access.<T> StaticFieldTypeRef<T>
ofType(TypeRef<T> type)
Sets the type reference of the field to access.
-
-
-
Method Detail
-
beginStaticFieldAccess
public static StaticFieldName beginStaticFieldAccess(java.lang.String name)
Creates a new
: the starting point of the fluent interface for accessing static fields using Java Reflection.StaticFieldName
- Parameters:
name
- the name of the field to access using Java Reflection.- Returns:
- the created
StaticFieldName
. - Throws:
java.lang.NullPointerException
- if the given name isnull
.java.lang.IllegalArgumentException
- if the given name is empty.
-
ofType
public <T> 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 isnull
.
-
ofType
public <T> StaticFieldTypeRef<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<String> commmonPowers =
staticField
("commonPowers").ofType
(newTypeRef
<List<String>>() {}).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 isnull
.
-
-