从动态调用java类获取返回值

时间:2015-06-08 05:11:42

标签: java reflection dynamic-method

我需要通过将变量值传递给该调用方法来动态调用java类来获取retrun值。我尝试使用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);

在那里我需要将值作为参数传递。但是这个方法需要给出参数类型。不是参数值。

我该怎么办?

1 个答案:

答案 0 :(得分:5)

在Method.invoke(...)中

,您不应传递参数类型,而应传递实际参数值。请查看Method.invoke(...)

的java文档
相关问题