package cn.itcast.day1;
public class ReflectPoint {
private int x;
public int y = 10;
public ReflectPoint(int x, int y) {
super();
this.x = x;
this.y = y;
}
}
ReflectPoint pt = new ReflectPoint(3, 5);
String variableName = "y";
Field field = getField(pt, variableName);
System.out.println(field.get(pt));
这样只能获取到对象初始化之后 y的值
有没有方法获取到类上y的值
|