Compartilhar via


MethodHandles.Invoker(MethodType) Method

Definition

Produces a special <em>invoker method handle</em> which can be used to invoke any method handle compatible with the given type, as if by MethodHandle#invoke invoke.

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

Parameters

type
MethodType

the desired target type

Returns

a method handle suitable for invoking any method handle convertible to the given type

Attributes

Remarks

Produces a special <em>invoker method handle</em> which can be used to invoke any method handle compatible with the given type, as if by MethodHandle#invoke invoke. The resulting invoker will have a type which is exactly equal to the desired type, except that it will accept an additional leading argument of type MethodHandle.

Before invoking its target, if the target differs from the expected type, the invoker will apply reference casts as necessary and box, unbox, or widen primitive values, as if by MethodHandle#asType asType. Similarly, the return value will be converted as necessary. If the target is a MethodHandle#asVarargsCollector variable arity method handle, the required arity conversion will be made, again as if by MethodHandle#asType asType.

This method is equivalent to the following code (though it may be more efficient): publicLookup().findVirtual(MethodHandle.class, "invoke", type)<p style="font-size:smaller;"> <em>Discussion:</em> A MethodType#genericMethodType general method type is one which mentions only Object arguments and return values. An invoker for such a type is capable of calling any method handle of the same arity as the general type. <p style="font-size:smaller;"> <em>(Note: The invoker method is not available via the Core Reflection API. An attempt to call java.lang.reflect.Method#invoke java.lang.reflect.Method.invoke on the declared invokeExact or invoke method will raise an java.lang.UnsupportedOperationException UnsupportedOperationException.)</em>

This method throws no reflective or security exceptions.

Java documentation for java.lang.invoke.MethodHandles.invoker(java.lang.invoke.MethodType).

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