Java Reflection Method Get from Object getMethod(Class klass, String methodName, Object... params)

Here you can find the source of getMethod(Class klass, String methodName, Object... params)

Description

get Method

License

Open Source License

Declaration

public static Method getMethod(Class<?> klass, String methodName, Object... params)
            throws SecurityException, NoSuchMethodException 

Method Source Code

//package com.java2s;
/*//from  w ww.  j a v  a 2s .c o  m
 *  This file is part of Cotopaxi.
 *
 *  Cotopaxi is free software: you can redistribute it and/or modify
 *  it under the terms of the Lesser GNU General Public License as published
 *  by the Free Software Foundation, either version 3 of the License, or
 *  any later version.
 *
 *  Cotopaxi is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  Lesser GNU General Public License for more details.
 *
 *  You should have received a copy of the Lesser GNU General Public License
 *  along with Cotopaxi. If not, see <http://www.gnu.org/licenses/>.
 */

import java.lang.reflect.Method;

public class Main {
    private static final Class<?>[] EMPTY_CLASS_PARAMS = new Class[0];

    public static Method getMethod(Class<?> klass, String methodName, Object... params)
            throws SecurityException, NoSuchMethodException {
        Class<?>[] classes = (params.length != 0) ? new Class<?>[params.length] : EMPTY_CLASS_PARAMS;

        for (int i = 0; i < params.length; i++) {
            classes[i] = params[i].getClass();
        }
        return klass.getMethod(methodName, classes);
    }

    /**
     * Gets an {@link Class} by name.
     */
    public static Class<?> getClass(String className) throws ClassNotFoundException {
        return Class.forName(className);
    }
}

Related

  1. getMethod(Class type, String name, Object[] args)
  2. getMethod(Class clz, String methodName, Class[] methodArgs)
  3. getMethod(Class type, String name, Class... parameterTypes)
  4. getMethod(Class cls, String method, Object[] params)
  5. getMethod(Class clz, String methodName, Object... params)
  6. getMethod(Class objectType, String methodName, Class... parameterTypes)
  7. getMethod(Class type, String name, Object[] args)
  8. getMethod(final Class clazz, final String methodName, final Class[] parTypes, final Object[] parameters)
  9. getMethod(final Object object, final String methodName, final Class... parameterClass)