我一直在尝试确定类中字段的类型.我已经看到了所有的内省方法,但还没有弄清楚如何做到这一点.这将用于从java类生成xml/json.我在这里看了很多问题,但还没找到我需要的东西.
例:
class Person {
public final String name;
public final List<Person> children;
}
Run Code Online (Sandbox Code Playgroud)
当我编组这个对象时,我需要知道该chidren字段是一个类型对象的列表Person,所以我可以正确地编组它.
我试过了
for (Field field : Person.class.getDeclaredFields()) {
System.out.format("Type: %s%n", field.getType());
}
Run Code Online (Sandbox Code Playgroud)
但是,这只会告诉我,这是一个List,不是List的Person小号
谢谢