gpt4 book ai didi

java - Objects getClass().getMethod 有什么用?

转载 作者:行者123 更新时间:2023-12-01 04:44:21 25 4
gpt4 key购买 nike

任何人都可以让我知道我们什么时候应该使用:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com