Here you can find the source of getMethods(Class> clazz, String name, int args)
public static Method[] getMethods(Class<?> clazz, String name, int args)
//package com.java2s; //License from project: LGPL import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; public class Main { public static Method[] getMethods(Class<?> clazz, String name, int args) { try {/*from w w w . j a va2 s . com*/ List<Method> list = new ArrayList<Method>(); for (Method method : clazz.getDeclaredMethods()) { if (method.getParameterTypes().length == args) { method.setAccessible(true); list.add(method); } } for (Method method : clazz.getDeclaredMethods()) if (method.getParameterTypes().length == args) list.add(method); return list.toArray(new Method[list.size()]); } catch (Throwable error) { return null; } } public static Method[] getMethods(Class<?> clazz, String name, boolean declared, int args) { try { List<Method> list = new ArrayList<Method>(); if (declared) { for (Method method : clazz.getDeclaredMethods()) { if (method.getParameterTypes().length == args) { method.setAccessible(true); list.add(method); } } } else for (Method method : clazz.getDeclaredMethods()) if (method.getParameterTypes().length == args) list.add(method); return list.toArray(new Method[list.size()]); } catch (Throwable error) { return null; } } public static Method[] getMethods(Class<?> clazz, String name, Class<?> result) { try { List<Method> list = new ArrayList<Method>(); for (Method method : clazz.getDeclaredMethods()) { if (method.getReturnType().getName().equals(result.getName())) { method.setAccessible(true); list.add(method); } } for (Method method : clazz.getDeclaredMethods()) if (method.getReturnType().getName().equals(result.getName())) list.add(method); return list.toArray(new Method[list.size()]); } catch (Throwable error) { return null; } } public static Method[] getMethods(Class<?> clazz, String name, boolean declared, Class<?> result) { try { List<Method> list = new ArrayList<Method>(); if (declared) { for (Method method : clazz.getDeclaredMethods()) { if (method.getReturnType().getName().equals(result.getName())) { method.setAccessible(true); list.add(method); } } } else for (Method method : clazz.getDeclaredMethods()) if (method.getReturnType().getName().equals(result.getName())) list.add(method); return list.toArray(new Method[list.size()]); } catch (Throwable error) { return null; } } }