Public static void main(String[] args) {
A A = new A();
system . out . println(getvalue infield(a," b 1 "," I "));
system . out . println(getvalue infield(a," b2 "," I));
system . out . println(getvalue infield(a," b3 "," I "));
}
Public static object getValueInField (object object, string field, string name) {
//The three parameters are the object obj of the external class, the reference name of the class as a member attribute, and the attribute name of the internal class to be queried.
Try {
Object o = obj.getClass()。 GetDeclaredField (field). get(obj);
returno.getClass()。 GetDeclaredField (name) get(o);
Catch (exception e) {
System.out.println ("search failed");
Returns null
}
}
}
Level a
B b 1 = new b (1);
B b2 = new b (2);
}
Class b {
int I;
B(int i){
this.i = i
}
}