Java Reflection Method Invoke invokeMethod(Object owner, String methodName, Object[] args)

Here you can find the source of invokeMethod(Object owner, String methodName, Object[] args)

Description

Invoke method.

License

Apache License

Parameter

Parameter Description
owner the owner
methodName the method name
args the args

Exception

Parameter Description
Exception the exception

Return

the object

Declaration

public static Object invokeMethod(Object owner, String methodName, Object[] args) throws Exception 

Method Source Code

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

import java.lang.reflect.Method;

public class Main {
    /**//from  w  ww  .  jav a2  s .  c  o  m
     * Invoke method.
     * 
     * @param owner
     *            the owner
     * @param methodName
     *            the method name
     * @param args
     *            the args
     * @return the object
     * @throws Exception
     *             the exception
     */
    public static Object invokeMethod(Object owner, String methodName, Object[] args) throws Exception {
        Class<?> ownerClass = owner.getClass();
        Class<?>[] argsClass = new Class[args.length];
        for (int i = 0, j = args.length; i < j; i++) {
            argsClass[i] = args[i].getClass();
        }
        Method method = ownerClass.getMethod(methodName, argsClass);
        return method.invoke(owner, args);
    }
}

Related

  1. invokeMethod(Object object, String methodName, Object[] params, Object[] result)
  2. invokeMethod(Object object, String name, Object... arguments)
  3. invokeMethod(Object object, String propertyName)
  4. invokeMethod(Object objectInstance, String methodToInvoke, Class[] parameterTypes, Object[] instanceParameters)
  5. invokeMethod(Object owner, String methodName)
  6. invokeMethod(Object parent, String method, Class[] paramTypes, Object[] args)
  7. invokeMethod(Object source, String method, Collection arguments)
  8. invokeMethod(Object sourceObject, String methodName, Object... arguments)
  9. invokeMethod(Object target, Class clazz, String methodName, Class[] types, Object[] args)

  10. HOME | Copyright © www.java2s.com 2016