这应该演示如何解决它:
import java.lang.reflect.Field;class Super { private int i = 5;}public class B extends Super { public static void main(String[] args) throws Exception { B b = new B(); Field f = b.getClass().getSuperclass().getDeclaredField("i"); f.setAccessible(true); System.out.println(f.get(b)); }}(或Class.getDeclaredFields用于所有字段的数组。)
输出:
5



