package 入学测试;
import java.beans.PropertyDescriptor;
import java.lang.reflect.*;
public class num4 {
public static void main(String[]args)throws Exception{
//结合泛型,使程序更安全
Constructor<person> ct=person.class.getConstructor(String.class,int.class);
person p=ct.newInstance("伍仪华",20);
String value="毕老师";
Method setName=p.getClass().getMethod("setName", String.class);
setName.invoke(p, value);
System.out.println(p.getName());
}
}
class person1 {
private String Name;
private int Age;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public int getAge() {
return Age;
}
public void setAge(int age) {
Age = age;
}
public person1(String name, int Age){
this.Name=Name;
this.Age=Age;
}
}
错在哪?求解释 |