任何人都可以让我知道我们什么时候应该使用:
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 语句是这样的?什么会被退回?
最佳答案
您的代码不正确,无法编译。
查看 Class 的 Javadoc。它只有一种叫做 getMethod 的方法:
getMethod(String name, Class<?>... parameterTypes)
它没有名为 getMethod() 的方法,该方法将 Method 对象作为第一个参数。
关于java - Objects getClass().getMethod 有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9430689/