我复制你的代码运行完全没问题啊。- import java.lang.reflect.Field;
- public class test {
- public static void main(String []args) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
- {
- ReflectPoint pt1=new ReflectPoint(3,5);
- Field fy=pt1.getClass().getField("y");
- System.out.println(fy.get(pt1));
- }
- }
- class ReflectPoint
- {
- private int x;
- public int y;
-
- public ReflectPoint(int x,int y)
- {
- super();
- this.x=x;
- this.y=y;
-
- }
- }
复制代码 只加了抛出异常的代码
运行结果 |
|