java反射 获取不到方法_在Java反射中找不到方法

我正在尝试使用以下代码从我的对象中提取方法:

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

它输出以下otput:

>>> 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.(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:实例对象是使用JCL从JAR实例化的,这可能是问题吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值