MethodHandles.ExactInvoker(MethodType) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Produces a special <em>invoker method handle</em> which can be used to
invoke any method handle of the given type, as if by MethodHandle#invokeExact invokeExact
.
[Android.Runtime.Register("exactInvoker", "(Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;", "", ApiSince=26)]
public static Java.Lang.Invoke.MethodHandle? ExactInvoker (Java.Lang.Invoke.MethodType? type);
[<Android.Runtime.Register("exactInvoker", "(Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;", "", ApiSince=26)>]
static member ExactInvoker : 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 of the given type
- Attributes
Remarks
Produces a special <em>invoker method handle</em> which can be used to invoke any method handle of the given type, as if by MethodHandle#invokeExact invokeExact
. 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
.
This method is equivalent to the following code (though it may be more efficient): publicLookup().findVirtual(MethodHandle.class, "invokeExact", type)
<p style="font-size:smaller;"> <em>Discussion:</em> Invoker method handles can be useful when working with variable method handles of unknown types. For example, to emulate an invokeExact
call to a variable method handle M
, extract its type T
, look up the invoker method X
for T
, and call the invoker method, as X.invoke(T, A...)
. (It would not work to call X.invokeExact
, since the type T
is unknown.) If spreading, collecting, or other argument transformations are required, they can be applied once to the invoker X
and reused on many M
method handle values, as long as they are compatible with the type of X
. <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.exactInvoker(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.