Java Reflection Method Name getMethodByName(Class clazz, String methodName)

Here you can find the source of getMethodByName(Class clazz, String methodName)

Description

get Method By Name

License

Open Source License

Declaration

public static Method getMethodByName(Class clazz, String methodName) 

Method Source Code

//package com.java2s;
/**************************************************************************************
 * Copyright (C) 2008 EsperTech, Inc. All rights reserved.                            *
 * http://esper.codehaus.org                                                          *
 * http://www.espertech.com                                                           *
 * ---------------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the GPL license       *
 * a copy of which has been included with this distribution in the license.txt file.  *
 **************************************************************************************/

import java.lang.reflect.*;

public class Main {
    public static Method getMethodByName(Class clazz, String methodName) {
        for (Method m : clazz.getMethods()) {
            if (m.getName().equals(methodName)) {
                return m;
            }//from ww w.  j  ava2s. com
        }
        throw new IllegalStateException(
                "Expected '" + methodName + "' method not found on interface '" + clazz.getName());
    }
}

Related

  1. getMethod(String name, Class pojoClass)
  2. getMethod(String name, Method method)
  3. getMethod(String name, String methodDesc, Class actual)
  4. getMethod(String strMethodPrefix, A instance, String strAttributeName, Class clazz)
  5. getMethodAsAccessible(String methodName, Class clazz)
  6. getMethodByName(Class aClass, String methodName, Class... params)
  7. getMethodByName(Class clazz, String methodName)
  8. getMethodByName(Class clazz, String methodName)
  9. getMethodByName(Class clazz, String name)