Java Reflection Method Name getMethod(Class c, String name, Class[] args)

Here you can find the source of getMethod(Class c, String name, Class[] args)

Description

Get method from class

License

Open Source License

Declaration

public static Method getMethod(Class<?> c, String name, Class<?>[] args) 

Method Source Code

//package com.java2s;

import java.lang.reflect.Method;

public class Main {
    /**//  ww  w.  j  a va 2  s . c om
     * Get method from class
     */
    public static Method getMethod(Class<?> c, String name, Class<?>[] args) {
        Method m = null;
        while (true) {
            try {
                m = c.getDeclaredMethod(name, args);
                break;
            } catch (NoSuchMethodException e) {
                c = c.getSuperclass();
                if (c == null) {
                    return null;
                }
            }
        }
        m.setAccessible(true);
        return m;
    }
}

Related

  1. getMethod(Class theClass, String propertyName)
  2. getMethod(Class type, String name, Class[] paramTypes)
  3. getMethod(Class beanClass, String methodName, Class[] types)
  4. getMethod(Class c, String name)
  5. getMethod(Class c, String name)
  6. getMethod(Class clazz, String methodName)
  7. getMethod(Class clazz, String methodName, Class fieldType)
  8. getMethod(Class clazz, String methodName, Class... arguments)
  9. getMethod(Class clazz, String methodName, Class... params)