e005. listing the property names of a bean.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 36 行

TXT
36
字号
This example determines the properties of a bean with the type MyBean. 
    try {
        BeanInfo bi = Introspector.getBeanInfo(MyBean.class);
        PropertyDescriptor[] pds = bi.getPropertyDescriptors();
        for (int i=0; i<pds.length; i++) {
            // Get property name
            String propName = pds[i].getName();
        }
        // class, prop1, prop2, PROP3
    } catch (java.beans.IntrospectionException e) {
    }
    
    public class MyBean {
        // Property prop1
        public String getProp1() {
            return null;
        }
        public void setProp1(String s) {
        }
    
        // Property prop2
        public int getProp2() {
            return 0;
        }
        public void setProp2(int i) {
        }
    
        // Property PROP
        public byte[] getPROP3() {
            return null;
        }
        public void setPROP3(byte[] bytes) {
        }
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?