public class A {
  public void foo(String name) {
    System.out.println("Hello, " + name);
  }
}

可以编写另外一个类来反射调用A上的方法: 

import java.lang.reflect.Method;

public class TestClassLoad {
  public static void main(String[] args) throws Exception {
    Class<?> clz = Class.forName("A");
    Object o = clz.newInstance();
    Method m = clz.getMethod("foo", String.class);
    for (int i = 0; i < 16; i++) {
      m.invoke(o, Integer.toString(i));
    }
  }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
  • 2022-12-23
  • 2021-07-11
  • 2021-06-14
  • 2021-11-11
  • 2021-10-31
猜你喜欢
  • 2022-12-23
  • 2021-11-06
  • 2021-05-26
  • 2021-08-08
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案