Java Reflection Method Parameter getMethod(Class klass, String methodName, Class[] parameterTypes)

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

Description

Returns the method object identified by the specified class, name and paramater types.

License

Open Source License

Parameter

Parameter Description
klass the class which method is searched in
methodName the method name
parameterTypes the method parameter types

Declaration

public static Method getMethod(Class klass, String methodName, Class[] parameterTypes) 

Method Source Code


//package com.java2s;

import java.lang.reflect.Method;

public class Main {
    /**//w  w  w.j  a  va  2 s  .  c  o  m
     * Returns the method object identified by the specified class, name and
     * paramater types. This method recursively check all the specified class
     * superclasses to find the method. Returns null if not found.
     * 
     * @param klass the class which method is searched in
     * @param methodName the method name
     * @param parameterTypes the method parameter types
     * 
     */
    public static Method getMethod(Class klass, String methodName, Class[] parameterTypes) {
        try {
            return klass.getDeclaredMethod(methodName, parameterTypes);

        } catch (NoSuchMethodException e) {
            if (klass.equals(Object.class))
                return null;

            return getMethod(klass.getSuperclass(), methodName, parameterTypes);
        }
    }
}

Related

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