package test;public class Outer { public class Inner{ public static final String aa="cc"; } } package test;import java.lang.reflect.Field;public class Reflection { public static void main(String[] args) { // TODO Auto-generated method stub try { Class c = null; //getDeclaredClasses获得所有内部类// Class[] cs = Outer.class.getDeclaredClasses();// // for(int i = 0 ; i < cs.length; i++){// // if(cs[i].getSimpleName().equals("Inner")){// c = cs[i];// break;// }// } c = Outer.class.forName("test.Outer$Inner"); Field f = c.getDeclaredField("aa"); f.setAccessible(true); System.out.println(f.get(null)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }}