Java Method Call invoke(Object target, String methodName, Object... args)

Here you can find the source of invoke(Object target, String methodName, Object... args)

Description

invoke

License

LGPL

Declaration

public static <E> E invoke(Object target, String methodName, Object... args) 

Method Source Code

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

import java.lang.reflect.Method;

public class Main {
    public static <E> E invoke(Object target, String methodName, Object... args) {
        for (Method method : target.getClass().getMethods()) {
            if (method.getName().equals(methodName)) {
                try {
                    return (E) method.invoke(target, args);
                } catch (Exception e) {
                    throw new RuntimeException("Exception invoking method " + methodName, e);
                }//from   w w  w. ja  v  a2s. c o m
            }
        }

        throw new RuntimeException("Method " + methodName + " not found");
    }
}

Related

  1. invoke(Object source, String key)
  2. invoke(Object target, Class clazz, String methodName, Class[] parameterTypes, Object... args)
  3. invoke(Object target, Class clazz, String method)
  4. invoke(Object target, Method method)
  5. invoke(Object target, String methodName)
  6. invoke(Object target, String methodName, Object[] args)
  7. invoke(Object target, String name, Class[] params, Object[] args)
  8. invoke(Object targetObject, String method, Class[] paramTypes, Object[] paramValues)
  9. invoke(Object targetObject, String methodName, Object... params)