GWT从对象动态获取变量
我有一些带有变量的对象供标准使用。在GWT中,我想做以下工作:GWT从对象动态获取变量,gwt,variables,object,Gwt,Variables,Object,我有一些带有变量的对象供标准使用。在GWT中,我想做以下工作: public class myObject { protected TextBox textbox1 = new TextBox(); protected TextBox textbox2 = new TextBox(); protected TextBox textbox3 = new TextBox(); protected TextBox textbox4 = new TextBox(); // pass
public class myObject {
protected TextBox textbox1 = new TextBox();
protected TextBox textbox2 = new TextBox();
protected TextBox textbox3 = new TextBox();
protected TextBox textbox4 = new TextBox();
// pass name of field: textbox1, textbox2... etc.
public TextBox getMyTextbox(String fieldname) {
return this.... [fieldname];
}
}
该部分返回此。。。这是我真正不明白的。欢迎您提供任何帮助。您觉得这里有什么让您困惑的地方:
public TextBox getMyTextbox(String fieldname) {
if ("textbox1".equals(fieldname) {
return textbox1;
} else if ("textbox2".equals(fieldname) {
return textbox2;
} else if ("textbox3".equals(fieldname) {
return textbox3;
} else if ("textbox4".equals(fieldname) {
return textbox4;
}
}
你会做一些你没有真正得到的事情吗?:)你为什么要这样做?:)这是什么。。。。[fieldname]?@milan:functional我做getMyTextbox,但我不知道怎么做,所以我不明白;-)。