Given:
public class A {
public int n;
public int func(Object arg) {...}
...
}
public class B {
private A myA;
...
}
private B myB;
When using reflection on myB
I get the field for myA
; how can I access the members and methods of class A
with it?
For example let's say I got a string "myA.n"
and given object myB
I need to access myA.n
Class<?> c = B.class; // or myB.getClass()
Field f = c.getField("myA");
int p = ???????? // reflection for int p = myA.n;
int q = ???????? // reflection for int q = myA.func(new Integer(3));