zoukankan      html  css  js  c++  java
  • 反射实例测试代码


    public
    class ReflectTest { public static void main(String[] args) { try { Class obj = ReflectTest.class.getClassLoader().loadClass("com.test.GetPackageName"); GetPackageName name = (GetPackageName) obj.getConstructor(String.class,String.class).newInstance("hello","xx"); System.out.println(name.toString()); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
        public GetPackageName() {
            System.out.println(" 构造函数");
        }
    
        public GetPackageName(String str) {
            System.out.println(str);
        }
        public GetPackageName(String str,String str2) {
            System.out.println("c2"+str+str2);
        }
  • 相关阅读:
    java面向对象day01
    找工作——JVM内存管理
    找工作——多线程
    找工作-——网络IO
    找工作--volatile
    找工作——异常处理
    找工作--设计模式
    Sqoop安装
    NIO
    Hadoop源码编译
  • 原文地址:https://www.cnblogs.com/kakaisgood/p/10214557.html
Copyright © 2011-2022 走看看