package com.jund.test;
public class TestVO {
private String name;
private String age;
private String address;
public String getName() {
System.out.println("this is getName");
return "----name";
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
System.out.println("this is getAge");
return "----age";
}
public void setAge(String age) {
this.age = age;
}
public String getAddress() {
System.out.println("this is getAge");
return "----address";
}
public void setAddress(String address) {
this.address = address;
}
}
package com.jund.test;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class GetMethod {
public static void main(String[] arg) throws Exception{
TestVO testVO = new TestVO();
Class extends TestVO> testClass = testVO.getClass();
//获得属性
Field[] fields = testVO.getClass().getDeclaredFields();
for (Field field : fields) {
PropertyDescriptor pd = new PropertyDescriptor(field.getName(), testClass);
//获得get方法
Method getMethod = pd.getReadMethod();
//执行get方法返回一个Object
Object obj = getMethod.invoke(testVO);
System.out.println(obj.toString());
}
}
}