0

I want to access all the fields with @customannotation in the class hierarchy .

The class structure is as follows:

Class A{
private Arraylist<B> b;
.
.
}
Class B{
@customannotation
private C c;
.
.
}
Class C{
@customannotation
private String c;
.
.
}

I tried class.getDeclaredClasses() but its returning 0 classes. Please help me out in recursive parsing to find all fields with @customannotation in the class hierarchy .

Akshatha
  • 1
  • 2
  • 1
    `getDeclaredClasses` doesn't make much sense since you don't want to access classes but fields, not to mention that these are top-level classes, not nested classes declared within other class. You need `getDeclaredFields`. – Pshemo Sep 07 '16 at 18:10
  • getDeclaredFields will not return fields of contained classes – Akshatha Sep 07 '16 at 18:14
  • Your class structure doesn't show that these classes are contained withing other class. If that is the case then please correct your example. – Pshemo Sep 07 '16 at 18:19
  • okay i want to access b class fields, which is variable of type B and further it has variable c, which is of type C. i should be able to get B & C class fields from Class A. – Akshatha Sep 07 '16 at 18:29

0 Answers0