public class Test_relect2 {
public static void main(String[] args) throws IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
BeanInfo info = Introspector.getBeanInfo(Man.class,Object.class);
PropertyDescriptor[] b = info.getPropertyDescriptors();
for (PropertyDescriptor pd : b) {
System.out.println(pd.getName() +"=="+pd.getPropertyType());
}
Man m = new Man();
// Method method = b[0].getWriteMethod();
// method.invoke(m, 12);
//
// method = b[0].getReadMethod();
// System.out.println(method.invoke(m, null));
PropertyDescriptor pd = new PropertyDescriptor("name", Man.class);
Method method = pd.getWriteMethod();
method.invoke(m, "coci");
method = pd.getReadMethod();
System.out.println(method.invoke(m,null));;
System.out.println();
}
}
class Man{
private String name ;
private int age;
private float money;
public String getName() {
return name;
}
public void invoke(Man m, String string) {
// TODO Auto-generated method stub
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public float getMoney() {
return money;
}
public void setMoney(float money) {
this.money = money;
}
}