Java Reflection Method Parameter getMethod(Class clazz, String functionName, Class[] parameterTypes)

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

Description

get Method

License

Apache License

Declaration

public static Method getMethod(Class<?> clazz, String functionName, 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<?> clazz, String functionName, Class<?>[] parameterTypes) {
        try {//from  www  .  ja v a 2  s  .  c o m
            Method function = clazz.getDeclaredMethod(functionName, parameterTypes);
            return function;
        } catch (Exception e) {
            if (parameterTypes.length > 0) {
                Method[] fList = clazz.getDeclaredMethods();
                loop: for (Method md : fList) {
                    Class<?>[] paramTypes = md.getParameterTypes();
                    if (!md.getName().equals(functionName))
                        continue loop;
                    if (paramTypes.length != parameterTypes.length)
                        continue loop;
                    for (int i = 0; i < parameterTypes.length; i++) {
                        if (!paramTypes[i].isAssignableFrom(parameterTypes[i]))
                            continue loop;
                    }
                    return md;
                }
            }

            Class<?> superClazz = clazz.getSuperclass();
            if (superClazz == Object.class) {
                return null;
            } else {
                return getMethod(superClazz, functionName, parameterTypes);
            }
        }
    }
}

Related

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