Java Reflection Method Name getMethod(Class cls, String name)

Here you can find the source of getMethod(Class cls, String name)

Description

Retrieve method with 0 parameter count and with given name from given class

License

Apache License

Parameter

Parameter Description
cls the class to retrieve from
name name of the method

Return

retrieved method

Declaration

public static Method getMethod(Class<?> cls, String name) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;

public class Main {
    /**/*from w  ww .j  ava  2 s .com*/
     * Retrieve method with 0 parameter count and with given name from given
     * class
     *
     * @param cls  the class to retrieve from
     * @param name name of the method
     * @return retrieved method
     * @see Class#getDeclaredMethod(String, Class...)
     */
    public static Method getMethod(Class<?> cls, String name) throws Exception {
        return getMethod(cls, name, new Class[0]);
    }

    /**
     * Retrieve method with given name and parameter types from given class
     *
     * @param cls            the class to retrieve from
     * @param name           name of the method
     * @param parameterTypes parameter types
     * @return retrieved method
     * @see Class#getDeclaredMethod(String, Class...)
     */
    public static Method getMethod(Class<?> cls, String name, Class<?>... parameterTypes) throws Exception {
        try {
            return cls.getDeclaredMethod(name, parameterTypes);
        } catch (Exception e) {
            throw e;
        }
    }
}

Related

  1. getMethod(Class clazz, String name, Class... args)
  2. getMethod(Class clazz, String name, Class... args)
  3. getMethod(Class clazz, String name, Class... params)
  4. getMethod(Class clazz, String name, int paramlength)
  5. getMethod(Class clazz, String... names)
  6. getMethod(Class cls, String name)
  7. getMethod(Class cls, String name, Class... types)
  8. getMethod(Class clss, String name, Class... params)
  9. getMethod(Class clz, String name)