【发布时间】:2013-07-26 05:29:53
【问题描述】:
我们开始吧,假设我有类名:
class Name {
String firstName, lastName;
// getters and setters, etc.
}
and then Name class's object is declared somewhere in other class :
class Other {
Name name;
// getter and setters, etc.
}
现在如果我做类似的事情:
Other o = new Other();
Field[] fields = o.getClass().getDeclaredFields();
fields[0] --> is 'name' the Object of 'Name' class
但是当我说field[0].getClass() 时:
它给了我java.lang.reflect.Field 类对象,而不是 Name 类对象。
如何从 'name'
等字段中获取 原始 类对象【问题讨论】:
标签: java reflection field