【问题标题】:Get a return value from dynamically calling java class [duplicate]从动态调用java类中获取返回值[重复]
【发布时间】:2015-08-22 11:23:44
【问题描述】:

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

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

我能做什么?

【问题讨论】:

标签: java reflection dynamic-method


【解决方案1】:

在 Method.invoke(...) 中,您不应该传递参数类型,而是传递实际的参数值。请查看 Method.invoke(...) 的 java 文档。

【讨论】:

    猜你喜欢
    • 2015-07-29
    • 2014-09-15
    • 2017-04-19
    • 1970-01-01
    • 2020-01-17
    • 2017-09-04
    • 1970-01-01
    • 2015-01-06
    • 2014-01-07
    相关资源
    最近更新 更多