zoukankan      html  css  js  c++  java
  • java反射

    public class TestPerson {
    
        private String name;
        
        private Integer sex;
    
        public String getName() {
            return "zhangsan";
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public Integer getSex() {
            return sex;
        }
    
        public void setSex(Integer sex) {
            this.sex = sex;
        }
    }
    public class Test {
    
        public static void main(String[] args) throws SQLException,
                PropertyVetoException, InstantiationException,
                IllegalAccessException {
            try {
                // Class clazz =
                // Class.forName("ZZY.src.cn.qtone.oa.test.TestPerson");
                TestPerson clazz = (TestPerson) Class.forName(
                        "cn.qtone.oa.test.TestPerson").newInstance();
                System.out.println(clazz.getName());
                ;
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    public class Test {
    
        public static void main(String[] args) throws SQLException,
                PropertyVetoException, InstantiationException,
                IllegalAccessException, IllegalArgumentException,
                InvocationTargetException {
            try {
                Class clazz = Class.forName("cn.qtone.oa.test.TestPerson");
                TestPerson testPerson = new TestPerson();
                Method[] methods = clazz.getMethods();
                for (Method m : methods) {
                    if (m.toString().indexOf("getName") > -1) {
                        System.out.println(m.invoke(testPerson));
                        ;
                    }
                    // System.out.println(m);
                }
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
  • 相关阅读:
    vsprintf解析
    带grub的软盘镜像制作
    SunnyOS准备4
    SunnyOS准备3
    SunnyOS准备1
    汇编第七日
    汇编第六日
    解决k8s集群中mount volume失败的问题
    更新k8s集群的证书
    为k8s集群配置自定义告警
  • 原文地址:https://www.cnblogs.com/chenweichu/p/6369395.html
Copyright © 2011-2022 走看看