A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 冯超 高级黑马   /  2012-9-16 15:18  /  1138 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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));
        }
}
为什么暴力反射不能了????

4 个回复

倒序浏览
Field fl = fp.getClass().getField("x");
该是
fl = fp.getClass().getDeclaredFileld("x");
回复 使用道具 举报
同楼上!
回复 使用道具 举报
1楼正解
回复 使用道具 举报
  谢谢······
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马