Here you can find the source of getMethodAsAccessible(String methodName, Class
public static <T> Method getMethodAsAccessible(String methodName, Class<T> clazz)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; public class Main { public static <T> Method getMethodAsAccessible(String methodName, Class<T> clazz) { for (Method each : clazz.getDeclaredMethods()) { Method result = methodIsCorrectOrNull(methodName, each); if (result != null) return result; }/* w w w . j a va2 s. c o m*/ for (Method each : clazz.getSuperclass().getDeclaredMethods()) { Method result = methodIsCorrectOrNull(methodName, each); if (result != null) return result; } throw new IllegalArgumentException("There is no method named " + methodName + " in class " + clazz); } private static Method methodIsCorrectOrNull(String methodName, Method each) { if (each.getName().equals(methodName)) { each.setAccessible(true); return each; } return null; } }