Java Reflection Method Get from Object getMethod(Object object, String name, Object... params)

Here you can find the source of getMethod(Object object, String name, Object... params)

Description

get method by name

License

Apache License

Parameter

Parameter Description
object container of method
name name of method
params params of method

Return

requested method

Declaration

public static Method getMethod(Object object, String name, Object... params) 

Method Source Code

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

import java.lang.reflect.Method;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /***/*from ww w. j av a2s.c o m*/
     * get method by name
     *
     * @param object container of method
     * @param name name of method
     * @param params params of method
     * @return requested method
     */
    public static Method getMethod(Object object, String name, Object... params) {
        try {
            List<Class> classParams = new ArrayList<>();
            for (int i = 0; i < params.length; i++) {
                classParams.add((Class) params[i]);
            }
            Class<?> classParamsArray[] = new Class[classParams.size()];
            classParams.toArray(classParamsArray);
            return object.getClass().getMethod(name, classParamsArray);
        } catch (NoSuchMethodException e) {
        }
        return null;
    }
}

Related

  1. getMethod(Object obj, String methodName)
  2. getMethod(Object obj, String methodName, Class paramClass)
  3. getMethod(Object obj, String methodName, Class... parameterTypes)
  4. getMethod(Object obj, String name, Class... types)
  5. getMethod(Object object, String methodName, Class... arguments)
  6. getMethod(Object oo, String mname)
  7. getMethod(Object pojo, String methodName, Class[] params)
  8. getMethod(Object target, String methodName)
  9. getMethod(Object target, String methodName, Class... parameterTypes)