Java Reflection Method Get from Object getMethod(Class objectClass, String methodName, String argumentType)

Here you can find the source of getMethod(Class objectClass, String methodName, String argumentType)

Description

get Method

License

BSD License

Declaration

public static Method getMethod(Class objectClass, String methodName, String argumentType) 

Method Source Code

//package com.java2s;
/*L//from w  w w .  j  av a  2 s .  c  om
 * Copyright Oracle Inc, SAIC-F.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/cadsr-bulk-loader/LICENSE.txt for details.
 */

import java.lang.reflect.Method;

public class Main {
    public static Method getMethod(Class objectClass, String methodName, String argumentType) {
        Method returnMethod = null;

        Method[] methods = objectClass.getMethods();
        int size = methods.length;

        for (int i = 0; i < size; i++) {
            Method method = methods[i];

            if (method.getName().equals(methodName)) {

                Class[] args = method.getParameterTypes();
                int argsize = args.length;

                if (argsize == 1) {
                    Class arg = args[0];

                    if (arg.getName().equals(argumentType)) {
                        returnMethod = method;
                        break;
                    }
                }
            }
        }

        return returnMethod;
    }
}

Related

  1. getMethod(Class aObject, String aMethod, Class... aParameterTypes)
  2. getMethod(Class c, String methodName, Object... pa)
  3. getMethod(Class type, String name, Object[] args)
  4. getMethod(Class clz, String methodName, Class[] methodArgs)
  5. getMethod(Class type, String name, Class... parameterTypes)
  6. getMethod(Class cls, String method, Object[] params)