鉴于:
public class A {
public int n;
public int func(Object arg) {...}
...
}
public class B {
private A myA;
...
}
private B myB;
当使用反射时,myB
我得到了myA
; 我如何访问它的成员和方法class A
?例如,假设我有一个字符串"myA.n"
并给定myB
我需要访问的对象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));