Accessing JavaBean Properties
Let's assume we have a simple class Person that defines the following property:
class Person {
private String name;
public String getName() {
return name;
}
public void setName(String newName) {
name = newName;
}
}
The following sections illustrate property access using FEST-Reflect. We will assume that we have the variable person of type Person. We are also going to assume the following static import:
import static org.fest.reflect.core.Reflection.property;
Reading the value of a property
The following code listing is equivalent to calling getName():
String name = property("name").ofType(String.class) .in(person) .get();
Setting the value of a property
The following code listing is equivalent to calling setName("Leia"):
property("name").ofType(String.class) .in(person) .set("Leia");
