I have a method callMethod that takes arguments: methodName (String) and parameters(Object[]). Now, everything seemed fine for me at the beginning, but I've stumbled upon a problem. You have to know the type of the Object to use reflection. So far I was determining it in such way:
Class[] getParameterTypes(Object[] parameters) {
Class[] parameterTypes = new Class[parameters.length];
for (int i = 0; i < parameters.length; i++) {
parameterTypes[i] = parameters[i].getClass();
}
return parameterTypes;
}
The callMethod is used to invoke method from external source. And it seems to fail when those methods have primitive parameters as types, or interfaces (List etc.) and I know why.
My question is: Is there any way around this to keep it that/similar way, or the only solution is to pass the type information (f.e Integer.TYPE for primitives etc.) to the method mentioned above:
callMethod(String methodName, Object[] parameters, Class[] parameterTypes);
Thanks for any help.