Produces a special invoker method handle which can be used to
invoke any method handle of the given type, as if by 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)
Discussion:
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.
(Note: The invoker method is not available via the Core Reflection API.
An attempt to call java.lang.reflect.Method.invoke
on the declared invokeExact or invoke method will raise an
UnsupportedOperationException.)
This method throws no reflective or security exceptions.
type | the desired target type |
IllegalArgumentException | if the resulting method handle's type would have too many parameters |
Diagram: MethodHandle