我有这样一个类:
public interface ControlService extends RemoteJsonService
{
public void myValues( String [] Names, AsyncCallback<Map<String,RegisterValues>> callback);
public class RegisterValues
{
int FirstField;
int SecondField;
//etc. 200 times
我有这样一个字符串:
String[] fieldValues = new String[]{"FirstField", "SecondField", ....}; //200 of these
我尝试调用这些字段(重要的部分在末尾):
public class RegistersPanel implements TestStandPanel, ChangeHandler
{
private ControlService service_;
public RegistersPanel(){
service_.RegisterValues( Names, new AsyncCallback<Map<String,ControlService.RegisterValues>>()
{
public void onSuccess( Map<String,ControlService.RegisterValues> result )
{
for( String Name : result.keySet() ){
for (String Values : fieldValues){
message+=result.get(Name).getField(Values); //something like this but I can't quite figure out the syntaxt
//message+=result.get(Name).FirstField; this is tedious
}
正如您所看到的,我不能只使用getField
,而且Eclipse没有给我任何有用的选项—任何建议吗?
我认为这是你在双循环中寻找的东西,
RegisterValues regValue=reuslt.get(Name);
regValue.getClass().getDeclaredField(Values).getInt(regValue);
这不是确切的解决方案。这使您能够访问该类中的字段值。注:如果把Values
改成value