本帖最后由 王钊 于 2013-2-26 14:27 编辑
- <P>class MyJavaBean
- {
- private boolean flag;
- private int age;
- private String name;
- private double number;
- public boolean isFlag()
- {
- return flag;
- }
- public void setFlag(boolean flag)
- {
- this.flag = flag;
- }
- public int getAge()
- {
- return age;
- }
- public void setAge(int age)
- {
- this.age = age;
- }
- public String getName()
- {
- return name;
- }
- public void setName(String name)
- {
- this.name = name;
- }
- public double getNumber()
- {
- return number;
- }
- public void setNumber(double number)
- {
- this.number = number;
- }
- }
- public class Test
- {
- public static void main(String[] args) throws Exception
- {
- MyJavaBean myJavaBean = new MyJavaBean();</P>
- <P> BeanInfo beanInfo = Introspector.getBeanInfo(myJavaBean.getClass());</P>
- <P> PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();</P>
- <P> for (int i = 0; i < pds.length; i++)
- {
- System.out.println(pds[i].getName());
- }
- /*输出:age
- class
- flag
- name
- number*/
- }
- }
- </P>
复制代码
我自己写了一个JavaBean,里面有四个属性,都生成了对应的setter和getter,
在主函数中我想用内省方式,获得他们的属性,把属性存入到PropertyDescriptor数组中,
打印他们的名字时,为什么会额外出来一个class??求高手帮个忙啊,详细点
|