Here you can find the source of invokeMethodHandleException(Method method, Object... args)
Parameter | Description |
---|---|
AssertionError | if error happened. |
public static Object invokeMethodHandleException(Method method, Object... args) throws InvocationTargetException
//package com.java2s; //License from project: Open Source License import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; public class Main { /**/* ww w .ja va 2 s . com*/ * Invokes given method with given arguments. * For instance method the 1st argument is used as {@code this}. * <br/> * Unlike {@link #invokeMethod(Method, Object...)} an exception thrown from target method is * not treated as error. * * @throws AssertionError if error happened. */ public static Object invokeMethodHandleException(Method method, Object... args) throws InvocationTargetException { try { method.setAccessible(true); if (Modifier.isStatic(method.getModifiers())) { return method.invoke(null, args); } else { Object this_ = args[0]; Object[] newArgs = new Object[args.length - 1]; System.arraycopy(args, 1, newArgs, 0, args.length - 1); return method.invoke(this_, newArgs); } } catch (IllegalAccessException e) { throw new AssertionError(e); } catch (IllegalArgumentException e) { throw new AssertionError(e); } } }