【发布时间】:2011-07-24 21:12:52
【问题描述】:
我需要编写代码来模拟在运行时在类中具有用户定义数量的可用字段。这个想法是能够将指向那些“动态”字段的 java.reflect.Field 对象返回给客户端代码。
class DynamicFieldClass {
/**
* fieldNames is the list of names of the fields we want to "exist" in the class
* they will all be of the same type (say String)
*/
public DynamicFieldClass(List<String> fieldNames) {
// ... what do we do here
}
public Field getFieldObjectFor(String desiredFieldName) {
// ... what do we do here
}
}
有没有类似于 DynamicProxy 的东西(但对于字段)? 谢谢
【问题讨论】:
标签: java reflection dynamic