Here you can find the source of getMethod(Class> type, String name, Class>... parameterTypes)
public static Method getMethod(Class<?> type, String name, Class<?>... parameterTypes)
//package com.java2s; /**/* w w w . j a v a2 s . c o m*/ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ import java.lang.reflect.Method; public class Main { public static final String CLINIT = "<clinit>"; public static final String INIT = "<init>"; public static Method getMethod(Class<?> type, String name, Class<?>... parameterTypes) { try { return myGetMethod(type, name, parameterTypes); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } } private static Method myGetMethod(Class<?> type, String name, Class<?>... parameterTypes) throws NoSuchMethodException { // Scan the type hierarchy just like Class.getMethod(String, Class[]) // using Class.getDeclaredMethod(String, Class[]) // System.out.println("type: " + type); // System.out.println("name: " + name); // System.out // .println("parameterTypes: " + Arrays.toString(parameterTypes)); try { // System.out.println("Checking getDeclaredMethod"); // for (Method m : type.getDeclaredMethods()) { // System.out.println("\t" + m); // } return type.getDeclaredMethod(name, parameterTypes); } catch (NoSuchMethodException e) { try { // Try the super classes if (type.getSuperclass() != null) { // System.out.println("Checking super: " // + type.getSuperclass()); return myGetMethod(type.getSuperclass(), name, parameterTypes); } } catch (NoSuchMethodException e2) { // Okay } // Try the super interfaces for (Class<?> superInterface : type.getInterfaces()) { try { // System.out.println("Checking super interface: " // + superInterface); return myGetMethod(superInterface, name, parameterTypes); } catch (NoSuchMethodException e3) { // Okay } } throw new NoSuchMethodException(type.getName() + '.' + getMethodSignature(name, parameterTypes)); } } public static String getMethodSignature(String name, Class<?>... parameterTypes) { StringBuilder builder = new StringBuilder(name); if (!(name.equals(CLINIT) || name.equals(INIT))) { builder.append('('); if (parameterTypes != null && parameterTypes.length > 0) { builder.append(parameterTypes[0].getName()); for (int i = 1; i < parameterTypes.length; i++) { builder.append(", ").append(parameterTypes[i].getName()); } } builder.append(')'); } return builder.toString(); } }