Module java.base

Interface MethodHandleInfo


public interface MethodHandleInfo
A symbolic reference obtained by cracking a direct method handle into its constituent symbolic parts. To crack a direct method handle, call Lookup.revealDirect.

Direct Method Handles

A direct method handle represents a method, constructor, or field without any intervening argument bindings or other transformations. The method, constructor, or field referred to by a direct method handle is called its underlying member. Direct method handles may be obtained in any of these ways:

Restrictions on Cracking

Given a suitable Lookup object, it is possible to crack any direct method handle to recover a symbolic reference for the underlying method, constructor, or field. Cracking must be done via a Lookup object equivalent to that which created the target method handle, or which has enough access permissions to recreate an equivalent method handle.

If the underlying method is caller sensitive, the direct method handle will have been "bound" to a particular caller class, the lookup class of the lookup object used to create it. Cracking this method handle with a different lookup class will fail even if the underlying method is public (like Class.forName).

The requirement of lookup object matching provides a "fast fail" behavior for programs which may otherwise trust erroneous revelation of a method handle with symbolic information (or caller binding) from an unexpected scope. Use MethodHandles.reflectAs(java.lang.Class<T>, java.lang.invoke.MethodHandle) to override this limitation.

Reference kinds

The Lookup Factory Methods correspond to all major use cases for methods, constructors, and fields. These use cases may be distinguished using small integers as follows:
reference kinds
reference kinddescriptive namescopememberbehavior
1REF_getFieldclass FT f;(T) this.f;
2REF_getStaticclass or interface static
FT f;
(T) C.f;
3REF_putFieldclass FT f;this.f = x;
4REF_putStaticclass static
FT f;
C.f = arg;
5REF_invokeVirtualclass T m(A*);(T) this.m(arg*);
6REF_invokeStaticclass or interface static
T m(A*);
(T) C.m(arg*);
7REF_invokeSpecialclass or interface T m(A*);(T) super.m(arg*);
8REF_newInvokeSpecialclass C(A*);new C(arg*);
9REF_invokeInterfaceinterface T m(A*);(T) this.m(arg*);
Since:
1.8