解决方案 »

  1.   

    Class<?> obj=Class.forName(ref.getClass().getName());
                Object object = obj.newInstance();
                Method method=obj.getMethod("getLength");你这样拿到的是你newInstance新构建的对象,又不是你之前设定了值的对象,域当然会是0.应该是这样:method.invoke(ref)
      

  2.   

    CSDN果然厉害,出现的第一个人就是高手,百度了好多reflect教程都没有指出这个问题,再次感谢
      

  3.   

    顺便说一句,刚才引用的代码都没用,这样写会比较好
    Class<?> clazz = ref.getClass();
    Method method=clazz.getMethod("getLength");
    System.out.println(method.invoke(ref));