Here you can find the source of getMethod(Class> clazz, String name, Class>... args)
public static Method getMethod(Class<?> clazz, String name, Class<?>... args)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; public class Main { public static Method getMethod(Class<?> clazz, String name, Class<?>... args) { for (Method m : clazz.getDeclaredMethods()) if (m.getName().equals(name) && (args.length == 0 && m.getParameterTypes().length == 0 || ClassListEqual(args, m.getParameterTypes()))) { m.setAccessible(true);/*w w w .j a v a2 s . com*/ return m; } for (Method m : clazz.getMethods()) if (m.getName().equals(name) && (args.length == 0 && m.getParameterTypes().length == 0 || ClassListEqual(args, m.getParameterTypes()))) { m.setAccessible(true); return m; } return null; } public static boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2) { if (l1.length != l2.length) return false; for (int i = 0; i < l1.length; i++) if (l1[i] != l2[i]) return false; return true; } }