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

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

Description

Gets the given method or throw exception.

License

Open Source License

Exception

Parameter Description
NoSuchMethodException an exception

Declaration

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

Method Source Code

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

import java.lang.reflect.Method;

public class Main {
    /**/*  w ww  .j  a va 2  s  . c o m*/
     * Gets the given method or throw exception.
     * @throws NoSuchMethodException
     */
    public static Method getMethod(Class<?> clss, String name, Class<?>... params) {
        try {
            return clss.getMethod(name, params);
        } catch (NoSuchMethodException e) {
            fatal("Method " + name + " does not exist", e);
            return null;
        }
    }

    /** Print fatal error and exit. */
    public static <T> T fatal(String message, Exception e) {
        System.out.println(message);
        if (e != null && System.getProperty("stacktrace") != null)
            e.printStackTrace();
        System.exit(0);
        return (T) null;
    }
}

Related

  1. getMethod(Class clazz, String name, int paramlength)
  2. getMethod(Class clazz, String... names)
  3. getMethod(Class cls, String name)
  4. getMethod(Class cls, String name)
  5. getMethod(Class cls, String name, Class... types)
  6. getMethod(Class clz, String name)
  7. getMethod(Class klass, String methodName)
  8. getMethod(Class klass, String methodName, Class requestClass)
  9. getMethod(Class klass, String methodName, Class... paramTypes)