zoukankan      html  css  js  c++  java
  • Eclipse里面有包下面的测试类调用默认包下面的类里面的方法

    1、通过Class的静态方法获取.

    Class clazz = Class.forName("类名");//将传入的类名所指定的类load到JVM内存中
    Method[] methods = clazz.getMethods();//获取该相关类所有的public类型的方法
    for (Method method : methods) {
      method.invoke(clazz.newInstance());//执行该对象的无参构造方法来创建该类的实例调用方法
    }
    Method method = clazz.getMethod("方法名");//根据方法名获取该相关类的public类型的方法
    method.invoke(clazz.newInstance());

    2、通过类的加载器

    ClassLoader classLoader = this.getClass().getClassLoader();//获取当前对象的类装载器
    Class clazz1 = classLoader.loadClass("类名");//通过类装载器加载需要的类

    Method[] methods = clazz1.getMethods();
    for (Method method : methods) {
      method.invoke(clazz1.newInstance());
    }
    Method method = clazz1.getMethod("方法名");
    method.invoke(clazz1.newInstance());

  • 相关阅读:
    Steady Cow Assignment POJ
    二分图多重匹配问题
    Tour HDU
    奔小康赚大钱 HDU
    Strategic Game HDU
    Antenna Placement POJ
    Oil Skimming HDU
    Rain on your Parade HDU
    假如,
    这样也可以,insert,,
  • 原文地址:https://www.cnblogs.com/bd195746/p/5813787.html
Copyright © 2011-2022 走看看