mardi 19 mai 2015

getDeclaredMethod with String.class parameter throws java.lang.NoSuchMethodException java.lang.String

I have a function that is basically

public myFunction (String rString, int rInt) { ... }

I'm playing around with reflections and getDeclaredMethod and trying to use that function as so

Class[] paramTypes = { String.class, int.class };

Method method = MyClass.class.getDeclaredMethod("myFunction", paramTypes);

Complies fine, but at run time I get the following error

java.lang.NoSuchMethodException: jp.website.com.mypackage.MyClass.myFunction(java.lang.String, int)

So, how I declare the String parameter so that it is passed to myFunction as a String and not as java.lang.String?

In full disclosure I'm using the MyClass.class.getDeclaredMethod("myFunction", paramTypes); in a JUnit test. Would that matter?





Aucun commentaire:

Enregistrer un commentaire