@Test public void testGetRestrictedFieldByReflection() throws Exception { BaseClass baseClass = new BaseClass(5); int a = (int) RestrictedFieldAccessingUtils.getRestrictedFieldByReflection(baseClass, "a", baseClass.getClass()); Assert.assertEquals(a, 5); }
public static Object getRestrictedFieldByReflection(Object containingObj, String fieldName, Class clazz) throws NoSuchFieldException, IllegalAccessException { Field field = clazz.getDeclaredField(fieldName); field.setAccessible(true); return field.get(containingObj); }
RestrictedFieldAccessingUtils { public static Object getRestrictedFieldByReflection(Object containingObj, String fieldName, Class clazz) throws NoSuchFieldException, IllegalAccessException { Field field = clazz.getDeclaredField(fieldName); field.setAccessible(true); return field.get(containingObj); } }
RestrictedFieldAccessingUtils { public static Object getRestrictedFieldByReflection(Object containingObj, String fieldName, Class clazz) throws NoSuchFieldException, IllegalAccessException { Field field = clazz.getDeclaredField(fieldName); field.setAccessible(true); return field.get(containingObj); } private  RestrictedFieldAccessingUtils(); }
RestrictedFieldAccessingUtils { public static Object getRestrictedFieldByReflection(Object containingObj, String fieldName, Class clazz) throws NoSuchFieldException, IllegalAccessException { Field field = clazz.getDeclaredField(fieldName); field.setAccessible(true); return field.get(containingObj); } private  RestrictedFieldAccessingUtils(); static Object getRestrictedFieldByReflection(Object containingObj, String fieldName, Class clazz); static Object getRestrictedFieldByReflectionRecursively(Object containingObj, String fieldName, Class clazz); }
RestrictedFieldAccessingUtils { public static Object getRestrictedFieldByReflection(Object containingObj, String fieldName, Class clazz) throws NoSuchFieldException, IllegalAccessException { Field field = clazz.getDeclaredField(fieldName); field.setAccessible(true); return field.get(containingObj); } private  RestrictedFieldAccessingUtils(); static Object getRestrictedFieldByReflection(Object containingObj, String fieldName, Class clazz); static Object getRestrictedFieldByReflectionRecursively(Object containingObj, String fieldName, Class clazz);  }