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();
            }
        }
    }
  • 相关阅读:
    VMware下Linux配置网络
    前端知识之查漏补缺二
    前端网络基础查漏补缺篇
    简单实现Promise
    前端知识之查漏补缺-1
    git tag
    云服务器安装node环境 mysql nginx
    js动画
    vue原理之双向绑定虚
    js的封装、继承与多态
  • 原文地址:https://www.cnblogs.com/chenweichu/p/6369395.html
Copyright © 2011-2022 走看看