先写ReflectPoint类:
import java.util.Date;
public class ReflectPoint
{
private int x;
private int y;
private Date birthday=new Date();
public Date getBirthday()
{
return birthday;
}
public void setBirthday(Date birthday)
{
this.birthday = birthday;
}
public ReflectPoint(int x, int y)
{
super();
this.x = x;
this.y = y;
}
public int getX()
{
return x;
}
public void setX(int x)
{
this.x = x;
}
public int getY()
{
return y;
}
public void setY(int y)
{
this.y = y;
}
}
然后写IntroSpectorTest类:
import org.apache.commons.beanutils.BeanUtils;
public class IntroSpectorTest
{
public static void main(String[] args)throws Exception
{
ReflectPoint pt1=new ReflectPoint(3,5);
System.out.println(BeanUtils.getProperty(pt1,"x"));
BeanUtils.setProperty(pt1,"x","9");
System.out.println(pt1.getX());
BeanUtils.setProperty(pt1,"birthday.time","111");
System.out.println(BeanUtils.getProperty(pt1,"birthday.time"));
}
}
运行结果如下: