Performs a variable arity invocation, passing the arguments in the given list to the method handle, as if via an inexact {@link #invoke invoke} from a call sitewhich mentions only the type {@code Object}, and whose arity is the length of the argument list.
Specifically, execution proceeds as if by the following steps, although the methods are not guaranteed to be called if the JVM can predict their effects.
- Determine the length of the argument array as {@code N}. For a null reference, {@code N=0}.
- Determine the general type {@code TN} of {@code N} arguments asas {@code TN=MethodType.genericMethodType(N)}.
- Force the original target method handle {@code MH0} to therequired type, as {@code MH1 = MH0.asType(TN)}.
- Spread the array into {@code N} separate arguments {@code A0, ...}.
- Invoke the type-adjusted method handle on the unpacked arguments: MH1.invokeExact(A0, ...).
- Take the return value as an {@code Object} reference.
Because of the action of the {@code asType} step, the following argumentconversions are applied as necessary:
- reference casting
- unboxing
- widening primitive conversions
The result returned by the call is boxed if it is a primitive, or forced to null if the return type is void.
This call is equivalent to the following code:
{@code MethodHandle invoker = MethodHandles.spreadInvoker(this.type(), 0); Object result = invoker.invokeExact(this, arguments);}
Unlike the signature polymorphic methods {@code invokeExact} and {@code invoke}, {@code invokeWithArguments} can be accessed normally via the Core Reflection API and JNI.It can therefore be used as a bridge between native or reflective code and method handles.
@param arguments the arguments to pass to the target
@return the result returned by the target
@throws ClassCastException if an argument cannot be converted by reference casting
@throws WrongMethodTypeException if the target's type cannot be adjusted to take the given number of {@code Object} arguments
@throws Throwable anything thrown by the target method invocation
@see MethodHandles#spreadInvoker