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

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

Description

invoke Method

License

Open Source License

Declaration

public static Object invokeMethod(Object obj, String method, Object... args) throws Exception 

Method Source Code

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

import java.lang.reflect.Method;

public class Main {
    public static Object invokeMethod(Object obj, String method, Object... args) throws Exception {
        Class<?>[] parameterTypes = new Class<?>[args.length];
        if (args.length > 0)
            for (int i = 0; i < args.length; i++)
                parameterTypes[i] = args[i].getClass();
        Method m = obj.getClass().getMethod(method, parameterTypes);
        if (!m.isAccessible())
            m.setAccessible(true);//from w  ww  . ja  v  a2 s .co m
        return m.invoke(obj, args);
    }
}

Related

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