有谁请让我知道我们什么时候应该使用:对象getClass()。getMethod的用途是什么?
Object.getClass().getMethod (action, null);
我发现这个属于Java反射包。我在问这个问题,因为在我们现有的应用程序中,我们有这个代码,但是我找不到它的用途。
Method action = null;
try {
action = getClass().getMethod (action, null);
}
catch (NoSuchMethodException x) {
}
return (TAPResponse) action.invoke (this, null);
在这种情况下,这是干什么的?
为什么是这样return语句?什么会被退回?
我怀疑这是现有应用程序中的代码,因为'getMethod'需要一个方法名称作为'String'而不是一个方法对象。 – stryba 2012-02-24 12:25:23
是的,这是我的应用程序内的代码。 – Kiran 2012-02-24 12:41:43
嗨,非常感谢你的回复,但是有没有人可以告诉我为什么返回类型是这样的? (因为invoke是java.lang.reflect.Method类的一部分,什么是TAPResponse在这里 – Kiran 2012-02-24 12:47:58