Method mothod1= person1.getClass().getMethod("setAge",int.class );
mothod1.invoke(person1, 39);
Method mothod2= person1.getClass().getMethod("setName",String.class );
mothod1.invoke(person1, "lala");
Field m1= person1.getClass().getField("age");
System.out.println(m1.get(person1));
Field m2= person1.getClass().getField("name");
System.out.println(m2.get(person1));
}
}
class Persion
{
public String name;
public int age;
public Persion(String name,int age){
this.name=name;
this.age=age;
}
public Persion(){
this.name="lili";
this.age=1;
}
public void setName(String name){
this.name=name;
}
public String getName(){
return this.name;
}
public void setAge(int age){
this.age=age;
}
public int getAge(){
return this.age;
}