Java Reflection Method Name getMethod(Class objClass, String methodName, Class argClass)

Here you can find the source of getMethod(Class objClass, String methodName, Class argClass)

Description

get Method

License

Open Source License

Parameter

Parameter Description
objClass a parameter
methodName a parameter
argClass a parameter

Exception

Parameter Description
Exception an exception

Return

Method

Declaration

public static Method getMethod(Class objClass, String methodName, Class argClass) throws Exception 

Method Source Code


//package com.java2s;

import java.lang.reflect.Method;

public class Main {
    /**//from   w  w  w.  ja  v  a2  s  .c om
     * get Method
     * 
     * @param objClass
     * @param methodName
     * @param argClass
     * @return Method
     * @throws Exception
     */
    public static Method getMethod(Class objClass, String methodName, Class argClass) throws Exception {
        Class argClasses[] = (argClass == null) ? null : new Class[] { argClass };
        return getMethod(objClass, methodName, argClasses);
    }

    /**
     * get Method
     * 
     * @param objClass
     * @param methodName
     * @param argClasses
     * @return
     * @throws Exception
     */
    public static Method getMethod(Class objClass, String methodName, Class argClasses[]) throws Exception {
        Method method = null;
        try {
            method = objClass.getDeclaredMethod(methodName, argClasses);
        } catch (Exception e) {
        }
        if (method == null) {
            try {
                method = objClass.getMethod(methodName, argClasses);
            } catch (Exception e) {
                // logger.debug(e);
            }
        }
        return method;
    }
}

Related

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