zoukankan      html  css  js  c++  java
  • java反射的四个加载器

    加载器是个好东西

    public static void main(String[] args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
            // 反射String类的所有构造方法
            Class clz = Student.class;
    
            System.out.println("所有构造方法");
            // Constructor[] cons = clz.getConstructors();
            Constructor[] cons = clz.getDeclaredConstructors();
            for (Constructor con : cons) {
                // System.out.println("访问修饰权限:" +
                // Modifier.toString(con.getModifiers()));
                // System.out.println("方法名:" + con.getName());
                // System.out.println("****************************");
                System.out.println(Modifier.toString(con.getModifiers()) + " "
                        + con.getName());
            }
    
            
            //找无参的构造方法    Student s = new Student();
            Constructor con = clz.getDeclaredConstructor();
            Object obj = con.newInstance();
            System.out.println(obj);
            
            //找带string,int类型参数的构造方法 Student s = new Student("zhangsan",12)
            con = clz.getDeclaredConstructor(String.class, int.class);
            obj = con.newInstance("zhangsan", 12);
            System.out.println(obj);
            
            con = clz.getDeclaredConstructor(String.class);
            
            }
  • 相关阅读:
    java中通过jacob调用dts进行数据导入导出
    Tomcat6 配置快逸报表
    [转]Sql Server Alter语句
    redhat linux卸载自带的Java1.4.2安装JDK6
    住房公积金额度计算
    JVisualVM使用
    Tomcat假死之问题原因排查
    JVM内存调优之监控篇
    tomcat之JVM GC 日志文件生成
    webstorm8的license
  • 原文地址:https://www.cnblogs.com/paoge/p/13542885.html
Copyright © 2011-2022 走看看