MessageDialog.openInformatiOn(null, null, new Entity().value("fatherName"));
public class Entity {
private String fatherName;
public String value(String name) {
if (name.equals("fatherName")) //-------> 如果我这两行不想明文编码,而是希望用RTTI反射来获值,
return fatherName; //-------> 请问要怎么写?
}
}
------解决思路----------------------
楼主是不是要的下面这种效果:
Field[] fileds = this.getClass().getDeclaredFields();
public String value(String name) {
for(Field field : fileds){
if(name.equals(field.getName()))
return field.getName();
}
return null;
}