本帖最后由 DOOR 于 2014-1-16 00:39 编辑
- class ReflectPoint
- {
- private int x;
- public int y;
- public ReflectPoint(int x,int y)
- {
- this.x = x;
- this.y = y;
- }
- }
- class Demo0707
- {
- public static void main(String[] args)
- {
- ReflectPoint rp = new ReflectPoint(3,5);
- Field fieldY = rp.getClass().getField("y");
-
- System.out.println(fieldY.get(rp));
- }
- }
复制代码 老报错,求解
还有代码上没写的,暴力反射有什么用?这个东西打破了封装性,有什么存在价值?
|