Java Method Call invoke(Object o, String m, Object... params)

Here you can find the source of invoke(Object o, String m, Object... params)

Description

invoke

License

Creative Commons License

Declaration

public static Object invoke(Object o, String m, Object... params) 

Method Source Code

//package com.java2s;
// This software is distributed under the following license:

import java.lang.reflect.*;

public class Main {
    public static Object invoke(Object o, String m, Object... params) {
        return invoke(o.getClass(), o, m, params);
    }// w  w w .j  av a2s. c  o m

    public static Object invoke(Class<?> c, Object o, String m, Object... params) {
        if (c == null) {
            return null;
        }
        Method methods[] = c.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].getName().equals(m)) {
                try {
                    methods[i].setAccessible(true);
                    return methods[i].invoke(o, params);
                } catch (Exception e) {
                }
            }
        }
        return invoke(c.getSuperclass(), o, m, params);
    }
}

Related

  1. invoke(Object instance, String method, Class[] paramTypes, Object... parameters)
  2. invoke(Object invoker, String cmd, Map params)
  3. invoke(Object methodHostInstance, String methodName, Class[] parameterTypes, Object[] args)
  4. invoke(Object o, Method m)
  5. invoke(Object o, Method method, Object... param)
  6. invoke(Object o, String method, Object... args)
  7. invoke(Object o, String name)
  8. invoke(Object o, String name, Object[] args)
  9. invoke(Object o, String name, Object[] args)