I have a question about reflection. I'm trying to use some kind of eval () method. Therefore, I can call, for example:
eval("test('woohoo')");
Now I understand that in java there is no eval method, but there is a reflection. I made the following code:
String s = "test"; Class cl = Class.forName("Main"); Method method = cl.getMethod(s, String.class); method.invoke(null, "woohoo");
This works fine (of course, there is an attempt to lock the lock around this code). It runs a testing method. However, I want to call several methods, all of which have different parameters.
I do not know what parameters are (so not only String.class). But how is this possible? How can I get the types of method parameters? I know about the following method:
Class[] parameterTypes = method.getParameterTypes();
But this will return the paramTypes of the method I just selected! with the following statement:
Method method = cl.getMethod(s, String.class);
Any help would be appreciated!
source share