Here you can find the source of invokeMethod(Object obj, Method method, Object... args)
public static Object invokeMethod(Object obj, Method method, Object... args)
//package com.java2s; //License from project: Apache License import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); public static Object invokeMethod(Object obj, Method method, Object... args) { Object result;//www . ja v a 2 s .c o m method.setAccessible(true); try { result = method.invoke(obj, args); } catch (IllegalAccessException | InvocationTargetException e) { logger.error("invoke method failure", e); throw new RuntimeException(e); } return result; } public static Object invokeMethod(MethodHandle methodHandle, Object... args) throws Throwable { return methodHandle.invoke(args); } }