开发者

Java getMethod throws method not found exception?

I am using the getMethod(String name) function to load a method bu开发者_Python百科t it always throws MethodNotFoundException. If I run class.getMethods() the method I am looking for is in that result with the exact name I am using to pass to getMethod(). The method I am trying to load is a static method so I don't know if getMethod() will not work for static methods. Any help?


If the method you're looking for takes any arguments, you need to pass their types to getMethod() as well. A Java method's signature (the thing that uniquely defines and identifies a method) is comprised of the method name and its parameter types.

http://download.oracle.com/javase/tutorial/java/javaOO/methods.html


The name isn't enough. You have to specify exactly which argument types you think the method takes, otherwise the query might be ambiguous (because Java supports overloading).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜