How can I determine the type of a generic field in Java?

前端 未结 7 924
无人共我
无人共我 2020-11-27 13:25

I have been trying to determine the type of a field in a class. I\'ve seen all the introspection methods but haven\'t quite figured out how to do it. This is going to be use

7条回答
  •  旧时难觅i
    2020-11-27 13:49

    take this snippet:

     for (Field field : Person.class.getFields()) {
            System.out.println(field.getType());
     }
    

    the key class is Field

提交回复
热议问题