Java Reflection Method Name getMethod(Class clazz, String name, Class... params)

Here you can find the source of getMethod(Class clazz, String name, Class... params)

Description

get Method

License

Open Source License

Parameter

Parameter Description
clazz The class to get the method for
name The name of the method
params The parameters of the method

Return

The method, if any

Declaration

public static Optional<Method> getMethod(Class<?> clazz, String name, Class<?>... params) 

Method Source Code

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

import java.lang.reflect.Method;
import java.util.Optional;

public class Main {
    /**/*from ww w  .j  a  v a 2 s  . c  om*/
     * @param clazz  The class to get the method for
     * @param name   The name of the method
     * @param params The parameters of the method
     *
     * @return The method, if any
     */
    public static Optional<Method> getMethod(Class<?> clazz, String name, Class<?>... params) {
        try {
            return Optional.of(clazz.getMethod(name, params));
        } catch (NoSuchMethodException ignored) {
        }

        try {
            return Optional.of(clazz.getDeclaredMethod(name, params));
        } catch (NoSuchMethodException ignored) {
        }

        return Optional.empty();
    }
}

Related

  1. getMethod(Class clazz, String name)
  2. getMethod(Class clazz, String name)
  3. getMethod(Class clazz, String name, boolean declared, Class... args)
  4. getMethod(Class clazz, String name, Class... args)
  5. getMethod(Class clazz, String name, Class... args)
  6. getMethod(Class clazz, String name, int paramlength)
  7. getMethod(Class clazz, String... names)
  8. getMethod(Class cls, String name)
  9. getMethod(Class cls, String name)