Get a return value from dynamically calling java class

1.3k Views Asked by At

I need to get a retrun value from dynamically calling java class by passing a variable values to that calling method. I try to use the java.lang.reflect.Method;

PredictionManager pm = new PredictionManager();
Class invokeclass = pm.getClass();

Class[] cArg = new Class[1];
cArg[0] = Integer.class;//Instances.class;

Method lMethod = invokeclass.getMethod("showLong", cArg);
Object aaa= lMethod.invoke(pm, cArg);

in there I need to pass the value as a argument. but this method needs to give the parameter type. not the parameter value.

What can I do?

1

There are 1 best solutions below

0
On BEST ANSWER

in Method.invoke(...) you should not pass the parameter types, but the actual parameter values. Please check the java documentation for Method.invoke(...).