简体   繁体   English

Java getMethod抛出方法未找到异常?

[英]Java getMethod throws method not found exception?

I am using the getMethod(String name) function to load a method but it always throws MethodNotFoundException . 我正在使用getMethod(String name)函数加载方法,但是它总是抛出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() . 如果我运行class.getMethods()那么我正在寻找的方法就是该结果中的确切名称,该名称正是我用来传递给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. 我尝试加载的方法是静态方法,所以我不知道getMethod()是否不适用于静态方法。 Any help? 有什么帮助吗?

If the method you're looking for takes any arguments, you need to pass their types to getMethod() as well. 如果您要查找的方法带有任何参数,则还需要将其类型传递给getMethod() A Java method's signature (the thing that uniquely defines and identifies a method) is comprised of the method name and its parameter types. Java方法的签名(唯一定义和识别方法的东西)是由方法的名称它的参数类型。

http://download.oracle.com/javase/tutorial/java/javaOO/methods.html 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). 您必须确切地指定认为该方法采用的参数类型,否则查询可能会模棱两可(因为Java支持重载)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM