Here you can find the source of getMethod(Class> clazz, String name, String returnType, String[] args)
public static Method getMethod(Class<?> clazz, String name, String returnType, String[] args)
//package com.java2s; /* Copyright Francesco Andreuzzi Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import java.lang.reflect.Method; public class Main { public static Method getMethod(Class<?> clazz, String name, String returnType, String[] args) { Method[] methods = clazz.getDeclaredMethods(); MainLoop: for (Method method : methods) { if (name != null && !name.equals(method.getName())) { continue; }//from w w w. jav a2 s . c o m if (returnType != null && !returnType.equals(method.getReturnType().getName())) { continue; } if (args != null) { Class<?>[] args2 = method.getParameterTypes(); if (args2.length != args.length) { continue; } for (int count = 0; count < args.length; count++) { if (!(args[count].equals(args2[count].getName()))) { continue MainLoop; } } } return method; } return null; } public static Method getMethod(Class<?> clazz, String name) { return getMethod(clazz, name, null, null); } public static Method getMethod(Class<?> clazz, Class<?> returnType) { return getMethod(clazz, null, returnType.getName(), null); } public static Method getMethod(Class<?> clazz, Class<?>[] args) { String[] params = new String[args.length]; for (int count = 0; count < params.length; count++) { params[count] = args[count].getName(); } return getMethod(clazz, null, null, params); } }