Java Reflection Method Parameter getMethod(Class c, String methodName, Class... parameterTypes)

Here you can find the source of getMethod(Class c, String methodName, Class... parameterTypes)

Description

get Method

License

Apache License

Declaration

public static Method getMethod(Class<?> c, String methodName, Class<?>... parameterTypes) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;

public class Main {
    public static Method getMethod(Class<?> c, String methodName, Class<?>... parameterTypes) {
        try {//from   w w  w  . ja va2  s .co m
            try {
                return c.getDeclaredMethod(methodName, parameterTypes);
            } catch (NoSuchMethodException ex) {
                Class<?> superclass = c.getSuperclass();
                if (superclass != null) {
                    return getMethod(superclass, methodName, parameterTypes);
                }

                return null;
            }
        } catch (RuntimeException ex) {
            throw ex;
        } catch (Exception ex) {
            // throw newstate ImplementationError(ex);
            throw new RuntimeException("");
        }
    }

    /**
     * Returns the declared method in the specified class or any of its super
     * classes.
     * 
     * @param c
     * @param methodName
     * @param types
     * @return
     * @throws NoSuchMethodException
     */
    public static Method getDeclaredMethod(Class<?> c, String methodName, Class<?>[] types)
            throws NoSuchMethodException {
        Method m = null;
        while (m == null && c != null) {
            try {
                m = c.getDeclaredMethod(methodName, types);
            } catch (SecurityException e) {
                throw new RuntimeException(e);
            } catch (NoSuchMethodException e) {
                // nop
            }
            c = c.getSuperclass();
        }
        if (m == null) {
            throw new NoSuchMethodException();
        }
        return m;
    }
}

Related

  1. getMethod(Class declaringClass, String name, Class... parameterTypes)
  2. getMethod(Class klass, String methodName, Class[] parameterTypes)
  3. getMethod(Class target, String methodName, Class[] parameterTypes)
  4. getMethod(Class type, String methodName, Class... parameterTypes)
  5. getMethod(Class type, String name, Class[] parameterTypes)
  6. getMethod(Class clazz, String functionName, Class[] parameterTypes)
  7. getMethod(Class clazz, String method, Class... parameterTypes)
  8. getMethod(Class clazz, String methodName, Class... parameterTypes)
  9. getMethod(Class clazz, String methodName, Class... parameterTypes)