public class flectPoint {
private int x;
public int y;
public flectPoint(int x, int y)
{
this.x = x;
this.y = y;
}
}
import java.lang.reflect.Field;
public class Test {
public static void main(String[] args) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
{
flectPoint fp = new flectPoint(3, 5);
Field fl = fp.getClass().getField("x");
fl.setAccessible(true);
System.out.println(fl.get(fp));
}
}
为什么暴力反射不能了???? |