Freigeben über


MethodHandles.SpreadInvoker(MethodType, Int32) Method

Definition

Produces a method handle which will invoke any method handle of the given type, with a given number of trailing arguments replaced by a single trailing Object[] array.

[Android.Runtime.Register("spreadInvoker", "(Ljava/lang/invoke/MethodType;I)Ljava/lang/invoke/MethodHandle;", "", ApiSince=26)]
public static Java.Lang.Invoke.MethodHandle? SpreadInvoker (Java.Lang.Invoke.MethodType? type, int leadingArgCount);
[<Android.Runtime.Register("spreadInvoker", "(Ljava/lang/invoke/MethodType;I)Ljava/lang/invoke/MethodHandle;", "", ApiSince=26)>]
static member SpreadInvoker : Java.Lang.Invoke.MethodType * int -> Java.Lang.Invoke.MethodHandle

Parameters

type
MethodType

the desired target type

leadingArgCount
Int32

number of fixed arguments, to be passed unchanged to the target

Returns

a method handle suitable for invoking any method handle of the given type

Attributes

Remarks

Produces a method handle which will invoke any method handle of the given type, with a given number of trailing arguments replaced by a single trailing Object[] array. The resulting invoker will be a method handle with the following arguments: <ul> <li>a single MethodHandle target <li>zero or more leading values (counted by leadingArgCount) <li>an Object[] array containing trailing arguments </ul>

The invoker will invoke its target like a call to MethodHandle#invoke invoke with the indicated type. That is, if the target is exactly of the given type, it will behave like invokeExact; otherwise it behave as if MethodHandle#asType asType is used to convert the target to the required type.

The type of the returned invoker will not be the given type, but rather will have all parameters except the first leadingArgCount replaced by a single array of type Object[], which will be the final parameter.

Before invoking its target, the invoker will spread the final array, apply reference casts as necessary, and unbox and widen primitive arguments. If, when the invoker is called, the supplied array argument does not have the correct number of elements, the invoker will throw an IllegalArgumentException instead of invoking the target.

This method is equivalent to the following code (though it may be more efficient): <blockquote>

{@code
            MethodHandle invoker = MethodHandles.invoker(type);
            int spreadArgCount = type.parameterCount() - leadingArgCount;
            invoker = invoker.asSpreader(Object[].class, spreadArgCount);
            return invoker;
            }

</blockquote> This method throws no reflective or security exceptions.

Java documentation for java.lang.invoke.MethodHandles.spreadInvoker(java.lang.invoke.MethodType, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to