Here you can find the source of getMethodByName(Class> clazz, String name)
private static Method getMethodByName(Class<?> clazz, String name)
//package com.java2s; import java.lang.reflect.Method; public class Main { private static Method getMethodByName(Class<?> clazz, String name) { Method method = getPublicMethodByName(clazz, name); if (method != null) return method; method = getProtectedMethodByName(clazz, name); if (method != null) return method; return null; }/*from w w w . ja va 2s.com*/ private static Method getPublicMethodByName(Class<?> clazz, String name) { Method[] methods = clazz.getMethods(); for (Method ele : methods) { if (name.equals(ele.getName())) return ele; } return null; } private static Method getProtectedMethodByName(Class<?> clazz, String name) { if (clazz == null) return null; Method[] methods = clazz.getDeclaredMethods(); for (Method ele : methods) { if (ele.isAccessible()) continue; if (name.equals(ele.getName())) return ele; } Method method = getProtectedMethodByName(clazz.getSuperclass(), name); if (method != null) return method; return null; } }