我正在尝试使用以下代码从我的对象中提取方法:
Method[] methods = instance.getClass().getMethods();
for (Method m : methods) {
System.out.println(">>> " + m.getName());
for (Class c : m.getParameterTypes()) {
System.out.println("\t->>> " + c.getName());
}
}
Object method = instance.getClass().getMethod("initialize", ComponentContext.class);
它打印以下输出:
>>> initialize
->>> org.hive.lib.component.ComponentContext
java.lang.NoSuchMethodException: org.hive.sample.Calculator.initialize(org.hive.lib.component.ComponentContext)
at java.lang.Class.getMethod(Class.java:1624)
at org.hive.container.lib.Component.hasRightParent(Component.java:140)
at org.hive.container.lib.Component.<init>(Component.java:118)
at org.hive.container.lib.ComponentController$AppLoader.execute(ComponentController.java:107)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
原始源代码:
class Calculator {
@Override
public void initialize(ComponentContext context) {
// Do nothing
}
}
怎么了?
添加:我已将获取方法更改为:
Object method = instance.getClass().getMethod("initialize", org.hive.lib.component.ComponentContext.class);
但仍然出现异常
ADD 2: instance
对象是用 JCL 从 JAR 实例化的,这可能是问题吗?