public class IntroSpectorTest {
/**
* @param args
*/
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
Persion p=new Persion("王五",21);
String propertyName="name";
PropertyDescriptor pd = new PropertyDescriptor(propertyName,p.getClass());
Method methodSetNAME = pd.getWriteMethod();
methodSetNAME.invoke(pd,"王五");//有错误
System.out.println(pd.getName());
}
//我想用set方法把名字赋值到Persion 类里,做不出来了 ,高手指点啊???
public class Persion {
public String name;
private int age;
public Persion(String name,int age){
super();
this.name=name;
this.age=age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
|
|