Java Reflection Method Name getMethod(Class targetClass, String methodName, Class[] paramTypes)

Here you can find the source of getMethod(Class targetClass, String methodName, Class[] paramTypes)

Description

get Method

License

Open Source License

Declaration

public static Method getMethod(Class targetClass, String methodName, Class[] paramTypes)
            throws NoSuchMethodException 

Method Source Code

//package com.java2s;
/*//from  w ww .  j a  v  a 2s.c om
 * This file is part of the Jose Project
 * see http://jose-chess.sourceforge.net/
 * (c) 2002-2006 Peter Sch?fer
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 */

import java.lang.reflect.Method;

public class Main {
    public static Method getMethod(Class targetClass, String methodName, Class[] paramTypes)
            throws NoSuchMethodException {
        Method method = null;
        NoSuchMethodException nsmex = null;
        for (Class clazz = targetClass; clazz != null; clazz = clazz.getSuperclass())
            try {
                method = clazz.getDeclaredMethod(methodName, paramTypes);
                break;
            } catch (NoSuchMethodException ex) {
                if (nsmex == null)
                    nsmex = ex;
                continue;
            }

        if (method == null && nsmex != null)
            throw nsmex;
        else
            return method;
    }
}

Related

  1. getMethod(Class cls, String methodName, Class[] params)
  2. getMethod(Class clz, String methodName, Class expectedTypes[])
  3. getMethod(Class klazz, String[] methodNames, int argCount)
  4. getMethod(Class objClass, String methodName, Class argClass)
  5. getMethod(Class serviceClass, String methodName, Class... mapClass)
  6. getMethod(Class targetClass, String name, Class paramClass)
  7. getMethod(Class targetClass, String targetMethodName)
  8. getMethod(Class theClass, String propertyName)
  9. getMethod(Class type, String name, Class[] paramTypes)