0

I have classes

class A {
   B b,
   C c,
}

class B {
   int d
}

class C {
   int e
}

If I ask for fields of A, I should get "b", "c", "b.d", "c.e". This could go to multiple levels.I dont want to do this on an object, only on the class. Is this possible to do? And if so can someone point me to the right direction?

Curiosa Globunznik
  • 3,129
  • 1
  • 16
  • 24
  • 1
    You can achieve this by A.getClass().getDeclaredFields(), then go with recursive function to resolve all names, but beware of cyclic references. This post gives an example: https://stackoverflow.com/questions/1780896/java-getting-the-properties-of-a-class-to-construct-a-string-representation – Beri Nov 18 '20 at 06:52
  • @NikolaiDmitriev how would json help? I dont want to do this on an object. only the class. Beri, Thanks will try it out – Antariksha Yelkawar Nov 18 '20 at 07:05
  • ok, that's different then. – Curiosa Globunznik Nov 18 '20 at 07:24

0 Answers0