【发布时间】:2014-05-03 13:23:35
【问题描述】:
我有一个这样的字符串:
String[] names = new String[] {"FirstMethod", "SecondMethod"...} //200 of these
目前我必须手动输入:
public void onSuccess( Map<String,ControlService.RegisterValues> result ) {
for( String Name : result.keySet() ){
message+=result.get(Name).FirstMethod+", ";
message+=result.get(Name).SecondMethod+", ";
//I call the method here - I'd like to use the list above to call it in though
显然我不想输入 200 次,有没有办法可以使用此列表,将其转换为方法名称,然后循环?
编辑:
我正在调用它的班级:
public interface ControlService extends RemoteJsonService
{
public void I2CRegisterValues( String [] Names, AsyncCallback<Map<String,RegisterValues>> callback);
public class RegisterValues
{
int FirstMethod;
//etc.
【问题讨论】:
-
result.get(Name).FirstMethod是对字段的访问,而不是方法。你的意思是result.get(Name).FirstMethod()? -
你想调用方法或者获取result.get(Name)对象中某个字段的值?
-
哈哈好吧,它在 Eclipse 上出现了一个蓝色三角形 - 所以我认为这是一种方法。我将使用我调用它的类来编辑上面的内容
-
“result.get(Name)”的结果是一个 ControlService.RegisterValues 类型的实例。这种类型真的声明了这么多方法吗?或者名称数组是否可以包含许多相同的方法名称?但是,尽管如此,您正在尝试的事情可以通过反射来实现。
-
我添加了调用它的方法。抱歉,我不太擅长行话(目前)