how to read object attribute dynamically in java?

后端 未结 5 1247
清歌不尽
清歌不尽 2021-02-07 12:38

Is there any way to read and print the object attribute dynamically(Java) ? for example if I have following object

public class A{
  int age ;
  String name;
           


        
5条回答
  •  忘了有多久
    2021-02-07 12:50

    You can use reflection to get every field from your object (if security configuration allows you).

    If you need it not for the sake of self-education, then it may be worth using ReflectionUtils from Apache Commons.

提交回复
热议问题