Here you can find the source of getMethod(Class> c, String methodName, Class>... parameterTypes)
public static Method getMethod(Class<?> c, String methodName, Class<?>... parameterTypes)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; public class Main { public static Method getMethod(Class<?> c, String methodName, Class<?>... parameterTypes) { try {//from w w w . ja va2 s .co m try { return c.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException ex) { Class<?> superclass = c.getSuperclass(); if (superclass != null) { return getMethod(superclass, methodName, parameterTypes); } return null; } } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { // throw newstate ImplementationError(ex); throw new RuntimeException(""); } } /** * Returns the declared method in the specified class or any of its super * classes. * * @param c * @param methodName * @param types * @return * @throws NoSuchMethodException */ public static Method getDeclaredMethod(Class<?> c, String methodName, Class<?>[] types) throws NoSuchMethodException { Method m = null; while (m == null && c != null) { try { m = c.getDeclaredMethod(methodName, types); } catch (SecurityException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { // nop } c = c.getSuperclass(); } if (m == null) { throw new NoSuchMethodException(); } return m; } }