Java Reflection Method Name getMethod(Class clazz, String methodName, Class argType)

Here you can find the source of getMethod(Class clazz, String methodName, Class argType)

Description

get Method

License

Apache License

Declaration

static java.lang.reflect.Method getMethod(Class clazz, String methodName, Class argType) 

Method Source Code

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

public class Main {
    static java.lang.reflect.Method getMethod(Class clazz, String methodName, Class argType) {
        try {//from  w  ww.  j av  a2 s  .c  om
            return clazz.getMethod(methodName, new Class[] { argType });
        } catch (Throwable ex) {
        }
        final java.lang.reflect.Method[] ms = clazz.getMethods();
        for (java.lang.reflect.Method m : ms) {
            if (!m.getName().equals(methodName))
                continue;
            // if( m.getModifiers()&Method.PUBLIC
            Class pramTypes[] = m.getParameterTypes();
            if (pramTypes.length == 1 && pramTypes[0].isAssignableFrom(argType))
                return m;
        }
        return null;
    }
}

Related

  1. getMethod(@Nonnull Class clazz, @Nonnull String methodName, @Nonnull Class... types)
  2. getMethod(Class c, String methodName)
  3. getMethod(Class c, String name)
  4. getMethod(Class cl, String methodName, Class[] paramTypes)
  5. getMethod(Class clazz, String methodName)
  6. getMethod(Class clazz, String methodName, Class[] classes)
  7. getMethod(Class clazz, String methodName, Class[] params)
  8. getMethod(Class clazz, String name)
  9. getMethod(Class clazz, String name, Class... args)