黑马程序员技术交流社区

标题: 反射问题 求解答!!!! [打印本页]

作者: @coffee    时间: 2015-2-4 00:10
标题: 反射问题 求解答!!!!
本帖最后由 @coffee 于 2015-2-5 15:33 编辑

package pack;

import java.lang.reflect.Constructor;


public class ReflectTest {

        /**
         * @param args
         */
        public static void main(String[] args)throws Exception {
                // TODO Auto-generated method stub
                ReflectPoint al = new ReflectPoint(3,5);
               
                Field fieldy = al.getClass().getField("y");

                System.out.println(fieldy.get(al));
        }

}


//被调用函数

public class ReflectPoint {
        
        private int x;
        public int y;
        public ReflectPoint(int x, int y) {
                super();
                this.x = x;
                this.y = y;
        }
}
/*错误提示:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
        Field cannot be resolved to a type

        at pack.ReflectTest.main(ReflectTest.java:41)

*/

作者: Imp_x    时间: 2015-2-4 18:47
你这代码在同一个JAVA文件里吧= =
作者: @coffee    时间: 2015-2-5 15:36
Imp_x 发表于 2015-2-4 18:47
你这代码在同一个JAVA文件里吧= =

恩!    多谢了 我已经知道错因啦:handshake




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2