Here you can find the source of getMethodFromClassWithInheritance(Class> cls, String methodName)
private static Method getMethodFromClassWithInheritance(Class<?> cls, String methodName)
//package com.java2s; /*/* w w w. j a va 2s. c o m*/ * The contents of this file are subject to the Automated Business Logic Public License Version 1.0 (the "License"), * which is derived from the Mozilla Public License version 1.1. You may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.automatedbusinesslogic.com/license/public-license * * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, * either express or implied. See the License for the specific language governing rights and limitations under the License. */ import java.lang.reflect.Method; public class Main { private static Method getMethodFromClassWithInheritance(Class<?> cls, String methodName) { Method theMethod = getMethodFromClass(cls, methodName); while (theMethod == null && (!cls.getName().equals("java.lang.Object"))) { cls = cls.getSuperclass(); theMethod = getMethodFromClass(cls, methodName); } return theMethod; } private static Method getMethodFromClass(Class<?> cls, String methodName) { Method[] allMethods = cls.getDeclaredMethods(); for (Method meth : allMethods) { if (!meth.getName().equals(methodName)) continue; return meth; } return null; } }