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

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

Description

Fail-safe getMethod.

License

Open Source License

Parameter

Parameter Description
clazz a parameter
methodName a parameter
arguments a parameter

Return

null in case of errors.

Declaration

public static Method getMethod(Class<?> clazz, String methodName, Class<?>... arguments) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Method;

public class Main {
    /**// w  w  w. j a  v a 2s  .com
     * Fail-safe getMethod.
     * @param clazz
     * @param methodName
     * @param arguments
     * @return null in case of errors.
     */
    public static Method getMethod(Class<?> clazz, String methodName, Class<?>... arguments) {
        try {
            return clazz.getMethod(methodName, arguments);
        } catch (NoSuchMethodException e) {
        } catch (SecurityException e) {
        }
        return null;
    }

    /**
     * Get a method matching one of the declared argument specifications.
     * @param clazz
     * @param methodName
     * @param argumentLists
     * @return The first matching method (given order).
     */
    public static Method getMethod(Class<?> clazz, String methodName, Class<?>[]... argumentLists) {
        Method method = null;
        for (Class<?>[] arguments : argumentLists) {
            method = getMethod(clazz, methodName, arguments);
            if (method != null) {
                return method;
            }
        }
        return null;
    }
}

Related

  1. getMethod(Class c, String name)
  2. getMethod(Class c, String name)
  3. getMethod(Class c, String name, Class[] args)
  4. getMethod(Class clazz, String methodName)
  5. getMethod(Class clazz, String methodName, Class fieldType)
  6. getMethod(Class clazz, String methodName, Class... params)
  7. getMethod(Class clazz, String methodName, Class... params)
  8. getMethod(Class clazz, String methodName, Class... params)
  9. getMethod(Class clazz, String methodName, Class... params)