Java Reflection Method Invoke invoke(Method method, Object object, Object... arguments)

Here you can find the source of invoke(Method method, Object object, Object... arguments)

Description

invoke

License

Open Source License

Declaration

public static Object invoke(Method method, Object object, Object... arguments) 

Method Source Code

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

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

import java.util.concurrent.Callable;

public class Main {
    public static Object invoke(Method method, Object object, Object... arguments) {
        return execute(() -> {
            method.setAccessible(true);//from w  w  w  .ja va2s . c  o  m
            return method.invoke(object, arguments);
        });
    }

    public static <T> T execute(Callable<T> reflectiveCall) {
        try {
            return reflectiveCall.call();
        } catch (RuntimeException rte) {
            throw rte;
        } catch (InvocationTargetException ite) {
            if (ite.getCause() instanceof RuntimeException) {
                throw (RuntimeException) ite.getCause();
            }
            throw new IllegalStateException(ite.getCause());
        } catch (Exception shouldNotHappen) {
            throw new IllegalStateException(shouldNotHappen);
        }
    }
}

Related

  1. invoke(Method method, Object javaBean, Object value)
  2. invoke(Method method, Object obj, Object... args)
  3. invoke(Method method, Object obj, Object... args)
  4. invoke(Method method, Object object, Object... args)
  5. invoke(Method method, Object object, Object... arguments)
  6. invoke(Method method, Object object, Object... parameters)
  7. invoke(Method method, Object object, Object[] args, Class exceptionToThrow)
  8. invoke(Method method, Object target, Object... args)
  9. invoke(Method method, Object target, Object... arguments)