This is my code to invoke a method dynamically:
String[] parameters = new String[requiredParameters.length];
//here i put some values in the parameters array
invoke
expects an Object[]
as second argument (varargs is just a convenience syntax).
I think in your case the String[]
is not taken as the first vararg argument, but the complete vararg Object[]
and thus your single strings are used as arguments which does not match String[]
.
In your case, explicitly wrapping your parameters in an Object
array before giving it to invoke
should work.
So do results = (ResultSet) method.invoke(new TestRecommendations(), new Ojbect[] { parameters })
instead