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());

  • 相关阅读:
    2012暑期川西旅游之第六天(四姑娘山达维夹金山邛崃青城山)
    实现元素拖拽
    asp.net学习资源
    080402 晴れ
    送给Rain的文章
    两天后见
    若水三千
    关于下一代的教育
    20080408 大雨
    Missing You
  • 原文地址:https://www.cnblogs.com/bd195746/p/5813787.html
Copyright © 2011-2022 走看看