在 Java 中是否可以通过名称获取类属性值?例如,我有课
public class Test {
private String field;
public String getField() {...}
public void setField() {...}
}
和另一个带地图的课程
public class Main {
private static final Map<String, Long> map = new HashMap<String, Long>();
static {
map.put("field", new Long(1));
}
public void doSth() {
Set<String> keys = map.keySet();
Test t = new Test();
for (String key : keys) {
//t.getPropertyValueByName(key); ?
}
}