public class javaBeanTest {
public static void main(String args[])throws Exception{
Class c=Person.class;
Constructor construtor=Class.forName("Person").getConstructor(String.class,int.class);//这个地方总提示出错,怎么解决啊?
Person person1=(Person)construtor.newInstance(new Person("zs",20));
Person person2=new Person();
String propertyName="name";
PropertyDescriptor pd=new PropertyDescriptor(propertyName,person2.getClass());
Method methodSetName=pd.getWriteMethod();
Object retVal=methodSetName.invoke(person2, "张三");
System.out.println(person2.getName());
}
} |
|