本帖最后由 杨增坤 于 2013-9-11 17:45 编辑
- import java.beans.BeanInfo;
- import java.beans.Introspector;
- import java.beans.PropertyDescriptor;
- import java.lang.reflect.Method;
- public class JavaBeanDemo1
- {
- public static void main(String[] args) throws Exception
- {
- NoteBook myNoteBook = new NoteBook("Lenovo G470", 4800);
- BeanInfo info = Introspector.getBeanInfo(myNoteBook.getClass());
- PropertyDescriptor[] pds = info.getPropertyDescriptors();
- for(PropertyDescriptor pd : pds)
- {
- System.out.println(pd.getName());
- }
- }
- }
- class NoteBook
- {
- private String name ;
- private int price;
- public NoteBook(String name , int price)
- {
- this.name = name ;
- this.price = price;
- }
- public void setName(String name )
- {
- this.name = name;
- }
- public String getName()
- {
- return this.name;
- }
- public void setPrice(int price)
- {
- this.price = price;
- }
- public int getPrice()
- {
- return this.price;
- }
- }
复制代码 为什么打印结果中第一行多一个class?
执行结果:
class
name
price
|