I am using the getMethod(String name) function to load a method but 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?
-
2Let's see the code that's failing and the output you feel validates your code. :)corsiKa– corsiKa2011-09-30 18:36:00 +00:00Commented Sep 30, 2011 at 18:36
-
It works for static methodes, too. That's not the problem. -> en.wikibooks.org/wiki/Java_Programming/Reflection/OverviewTobias– Tobias2011-09-30 18:36:41 +00:00Commented Sep 30, 2011 at 18:36
Add a comment
|
2 Answers
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
1 Comment
Kirk Woll
+1, and if it's non-public you need to use
getDeclaredMethod instead.