Java Reflection Method Invoke invokeMethod(Object obj, String methodname, Object... args)

Here you can find the source of invokeMethod(Object obj, String methodname, Object... args)

Description

invoke Method

License

Open Source License

Declaration

public static void invokeMethod(Object obj, String methodname, Object... args) 

Method Source Code

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

import java.lang.reflect.Method;

public class Main {
    public static void invokeMethod(Object obj, String methodname, Object... args) {
        Class<?> clazz = obj.getClass();
        do {//from  w  w  w.  j  a  v a 2s.c  om
            try {
                for (Method method : clazz.getDeclaredMethods()) {
                    if (method.getName().equals(methodname) && method.getParameterTypes().length == args.length) {
                        method.setAccessible(true);
                        method.invoke(obj, args);
                    }
                }
            } catch (Throwable t) {
            }
        } while ((clazz = clazz.getSuperclass()) != null);
    }
}

Related

  1. invokeMethod(Object obj, String mehtodName, Object... parameter)
  2. invokeMethod(Object obj, String method)
  3. invokeMethod(Object obj, String method, Object... args)
  4. invokeMethod(Object obj, String methodName, Object... args)
  5. invokeMethod(Object obj, String methodName, Object... args)
  6. invokeMethod(Object obj, String methodName, Object... params)
  7. invokeMethod(Object obj, String methodName, Object[] params, Class[] paramTypes)
  8. invokeMethod(Object object, Method method, Object... args)
  9. invokeMethod(Object object, String methodName, Class[] parameterTypes, Object[] parameters)