Java Method Call invoke(String methodName, Object object, Class[] argTypes, Object[] args)

Here you can find the source of invoke(String methodName, Object object, Class[] argTypes, Object[] args)

Description

invoke

License

Open Source License

Declaration

public static Object invoke(String methodName, Object object, Class<?>[] argTypes, Object[] args)
            throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
            InvocationTargetException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.// w w w. j a v a  2  s.com
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 *******************************************************************************/

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    public static Object invoke(String methodName, Object object, Class<?>[] argTypes, Object[] args)
            throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
            InvocationTargetException {

        Method method = object.getClass().getDeclaredMethod(methodName, argTypes);
        method.setAccessible(true);

        return method.invoke(object, args);
    }
}

Related

  1. invoke(Optional method, Class clazz, Object... args)
  2. invoke(String className, String methodName, Class[] paramTypes, Object... params)
  3. invoke(String cls_name, String method, Class[] param_cls, Object cls, Object[] params)
  4. invoke(String method)
  5. invoke(String methodName, Object obj)
  6. invoke(String methodName, Object target, Class targetClass, Object[] args)
  7. invoke(String name, Object object, Object... args)
  8. invoke_ex(Object obj, String method, Class[] params, Object[] args)
  9. invokeAccessableMethodWithArguments(Object instance, String method, Object... arguments)