ReflectionUtils { public static <M extends Member> M forceAccessible(M member) { if ((member.getDeclaringClass().getModifiers() & Modifier.PUBLIC) == 0 || (member.getModifiers() & Modifier.PUBLIC) == 0) { if (member instanceof AccessibleObject) { AccessibleObject accessibleMember = (AccessibleObject) member; if (!accessibleMember.isAccessible()) { accessibleMember.setAccessible(true); } } } return member; }  static String getSimpleName(Class<?> klass); static String getPrettyName(Class<?> klass); static @Nullable Method findMethod(Class<?> klass, Class<? extends Annotation> annotation,
      Class<?>... signature); static Object invoke(Method method, Object self); static Object readField(Class<?> klass, String name); static Object readField(Class<?> klass, @Nullable Object self, String name); static M forceAccessible(M member); static void invokePostConstruct(List<?> objects); static void invokePreDestroy(List<?> objects); static final Function<Object, String> TO_SIMPLECLASSNAME; static final Function<Object, String> TO_CLASSNAME; static final Function<Object, String> TO_PRETTYCLASSNAME; }
@Test public void testForceAccessible() throws SecurityException, NoSuchMethodException { ReflectionUtils.forceAccessible(String.class.getMethod("length")); ReflectionUtils.forceAccessible(ReflectionUtilsTest.class.getDeclaredMethod("privateMethod")); }