Here you can find the source of getMethodByName(Class> clazz, String methodName)
private static Method getMethodByName(Class<?> clazz, String methodName)
//package com.java2s; /*/* w w w. ja va2 s . co m*/ * Copyright 2012 Ryan W Tenney (http://ryan.10e.us) * and Martello Technologies (http://martellotech.com) * * 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; import java.util.ArrayList; import java.util.List; public class Main { private static Method getMethodByName(Class<?> clazz, String methodName) { List<Method> methodsFound = new ArrayList<Method>(); for (Method method : clazz.getMethods()) { if (method.getName().equals(methodName)) { methodsFound.add(method); } } if (methodsFound.size() == 1) { return methodsFound.get(0); } else { throw new RuntimeException("No unique method " + methodName + " found on class " + clazz.getName()); } } }