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

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

Description

get Method

License

Apache License

Declaration

public static Method getMethod(Class<?> clz, 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<?> clz, String methodName, Class<?>... parameterTypes) {

        try {/*from  ww  w .  j  ava  2 s .  com*/
            Method m = clz.getDeclaredMethod(methodName, parameterTypes);
            return m;
        } catch (NoSuchMethodException | SecurityException e) {
            return getMethodByNameSimple(clz, methodName);
        }
    }

    public static Method getMethodByNameSimple(Class<?> clz, String methodName) {
        Method[] methods = clz.getDeclaredMethods();

        for (Method method : methods) {
            if (method.getName().equals(methodName)) {
                return method;
            }
        }

        return null;
    }
}

Related

  1. getMethod(Class clazz, String methodName, Class... parameterTypes)
  2. getMethod(Class clazz, String name, Class... parameterTypes)
  3. getMethod(Class clazz, String name, Class... parameterTypes)
  4. getMethod(Class clazz, String name, Class[] parameterTypes)
  5. getMethod(Class cls, String name, Class... parameterTypes)
  6. getMethod(Class declaringClass, String name, Class... parameterTypes)
  7. getMethod(Class declaringType, String methodName, Class... parameterTypes)
  8. getMethod(Class instance, String method, Class... parameters)
  9. getMethod(Class sourceClass, boolean isFindDeclaredMethod, boolean isUpwardFind, String methodName, Class... methodParameterTypes)