本帖最后由 @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)
*/
|
|