Here you can find the source of getMethodRecursive(final Class> clazz, final String methodName, final Class>... parameterTypes)
public static Method getMethodRecursive(final Class<?> clazz, final String methodName, final Class<?>... parameterTypes)
//package com.java2s; /******************************************************************************* * Portions created by Sebastian Thomschke are copyright (c) 2005-2016 Sebastian * Thomschke.//from www . j av a2 s . co m * * All Rights Reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Sebastian Thomschke - initial implementation. *******************************************************************************/ import java.lang.reflect.Method; public class Main { /** * @return the method or null if the method does not exist */ public static Method getMethodRecursive(final Class<?> clazz, final String methodName, final Class<?>... parameterTypes) { final Method m = getMethod(clazz, methodName, parameterTypes); if (m != null) return m; final Class<?> superclazz = clazz.getSuperclass(); if (superclazz == null) return null; return getMethodRecursive(superclazz, methodName, parameterTypes); } /** * @return the method or null if the method does not exist */ public static Method getMethod(final Class<?> clazz, final String methodName, final Class<?>... parameterTypes) { try { return clazz.getDeclaredMethod(methodName, parameterTypes); } catch (final NoSuchMethodException ex) { return null; } } }