I have a method that helps to invoke a known method
public static void invoke(Object object, Class<?> callingClass, String methodName, Object[] param)
I was able to invoke this
for (Method method : callingClass.getDeclaredMethods()) {
if (method.getName().equals("bla")) {
method.invoke(object, param);
}
}
But when I tried to call
Class[] paramClass = new Class[param.length];
for (int i = 0; i < paramClass.length; i++) {
paramClass[i] = Class.forName(param[i].getClass().getName());
}
Method method = callingClass.getDeclaredMethod(methodName, paramClass);
I encountered java.lang.NoSuchMethodException. The method that I tried to invoke is
public void bla(String[] arg, Map<String, String[]> argContext);
And I passed in my "invoke" method the above, just for the param, an array consists of a String[] object, and a Map object retrieved from Collections.unmodifiableMap(source)
I guess the problem comes from the fact that my input is UnmodifiableMap where the bla method requires a regular Map. What's the work around for this? Thanks