PropertyDescriptor[] ps = Introspector.getBeanInfo(bean.getClass()).getPropertyDescriptors()方法用于获取的类的属性
获取的属性不是类的成员变量。
例如:
package junit.test;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
public class Bean {
public String name;
public void setNameTest(String name) {
this.name = name;
}
public static void main(String[] args) {
try {
PropertyDescriptor[] pds = Introspector.getBeanInfo(Bean.class).getPropertyDescriptors();
for(PropertyDescriptor pd : pds){
System.out.println(pd.getName());
}
} catch (IntrospectionException e) {
e.printStackTrace();
}
}
}
输出的结果为
class
nameTest
所以类的成员变量不是类的属性