Lookup.revealDirect
.
ldc
instruction on a CONSTANT_MethodHandle
constant.
(See the Java Virtual Machine Specification, sections 4.4.8 and 5.4.3.)
Lookup.findVirtual
,
to resolve a symbolic reference into a method handle.
A symbolic reference consists of a class, name string, and type.
Lookup.unreflect
or Lookup.unreflectSpecial
to convert a Method
into a method handle.
Lookup.unreflectConstructor
to convert a Constructor
into a method handle.
Lookup.unreflectGetter
or Lookup.unreflectSetter
to convert a Field
into a method handle.
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 java.
to override this limitation.
reference kind | descriptive name | scope | member | behavior |
---|---|---|---|---|
1 | REF_getField | class |
FT f; | (T) this.f; |
2 | REF_getStatic | class or interface |
static FT f; | (T) C.f; |
3 | REF_putField | class |
FT f; | this.f = x; |
4 | REF_putStatic | class |
static FT f; | C.f = arg; |
5 | REF_invokeVirtual | class |
T m(A*); | (T) this.m(arg*); |
6 | REF_invokeStatic | class or interface |
static T m(A*); | (T) C.m(arg*); |
7 | REF_invokeSpecial | class or interface |
T m(A*); | (T) super.m(arg*); |
8 | REF_newInvokeSpecial | class |
C(A*); | new C(arg*); |
9 | REF_invokeInterface | interface |
T m(A*); | (T) this.m(arg*); |
Modifier and Type | Field and Description |
---|---|
public static final int | REF_getField
A direct method handle reference kind, as defined in the table above. |
public static final int | REF_getStatic
A direct method handle reference kind, as defined in the table above. |
public static final int | REF_invokeInterface
A direct method handle reference kind, as defined in the table above. |
public static final int | REF_invokeSpecial
A direct method handle reference kind, as defined in the table above. |
public static final int | REF_invokeStatic
A direct method handle reference kind, as defined in the table above. |
public static final int | REF_invokeVirtual
A direct method handle reference kind, as defined in the table above. |
public static final int | REF_newInvokeSpecial
A direct method handle reference kind, as defined in the table above. |
public static final int | REF_putField
A direct method handle reference kind, as defined in the table above. |
public static final int | REF_putStatic
A direct method handle reference kind, as defined in the table above. |
Modifier and Type | Method and Description |
---|---|
public Class | Returns: the declaring class of the underlying memberReturns the class in which the cracked method handle's underlying member was defined. |
public MethodType | Returns: the type of the underlying member, expressed as a method typeReturns the nominal type of the cracked symbolic reference, expressed as a method type. |
public int | Returns: the Java language modifiers for underlying member, or -1 if the member cannot be accessedReturns the access modifiers of the underlying member. |
public String | Returns: the simple name of the underlying memberReturns the name of the cracked method handle's underlying member. |
public int | Returns: the integer code for the kind of reference used to access the underlying memberReturns the reference kind of the cracked method handle, which in turn determines whether the method handle's underlying member was a constructor, method, or field. |
public default boolean | Returns: true if and only if the underlying member was declared with variable arity.Determines if the underlying member was a variable arity method or constructor. |
public static String | Returns: a mixed-case string such as"getField" an integer code for a kind of reference used to access a class member referenceKind)Returns the descriptive name of the given reference kind, as defined in the table above. |
public < the desired type of the result, either T extends Member> TMember or a subtype | Returns: a reference to the method, constructor, or field objecta class object representing the desired result type expected, MethodHandles.T the lookup object that created this MethodHandleInfo, or one with equivalent access privileges lookupReflects the underlying member as a method, constructor, or field object. |
public static String | Returns: a string of the form"RK C.N:MT" the reference kind part of the symbolic reference kind, Class<?> the declaring class part of the symbolic reference defc, String the member name part of the symbolic reference name, MethodType the method type part of the symbolic reference type)Returns a string representation for a |
REF_getField | back to summary |
---|---|
public static final int REF_getField A direct method handle reference kind, as defined in the table above. |
REF_getStatic | back to summary |
---|---|
public static final int REF_getStatic A direct method handle reference kind, as defined in the table above. |
REF_invokeInterface | back to summary |
---|---|
public static final int REF_invokeInterface A direct method handle reference kind, as defined in the table above. |
REF_invokeSpecial | back to summary |
---|---|
public static final int REF_invokeSpecial A direct method handle reference kind, as defined in the table above. |
REF_invokeStatic | back to summary |
---|---|
public static final int REF_invokeStatic A direct method handle reference kind, as defined in the table above. |
REF_invokeVirtual | back to summary |
---|---|
public static final int REF_invokeVirtual A direct method handle reference kind, as defined in the table above. |
REF_newInvokeSpecial | back to summary |
---|---|
public static final int REF_newInvokeSpecial A direct method handle reference kind, as defined in the table above. |
REF_putField | back to summary |
---|---|
public static final int REF_putField A direct method handle reference kind, as defined in the table above. |
REF_putStatic | back to summary |
---|---|
public static final int REF_putStatic A direct method handle reference kind, as defined in the table above. |
getDeclaringClass | back to summary |
---|---|
public Class Returns the class in which the cracked method handle's underlying member was defined.
|
getMethodType | back to summary |
---|---|
public MethodType getMethodType() Returns the nominal type of the cracked symbolic reference, expressed as a method type.
If the reference is to a constructor, the return type will be
Note that original direct method handle may include a leading
|
getModifiers | back to summary |
---|---|
public int getModifiers() Returns the access modifiers of the underlying member. |
getName | back to summary |
---|---|
public String getName() Returns the name of the cracked method handle's underlying member. This is <init> if the underlying member was a constructor, else it is a simple method name or field name.
|
getReferenceKind | back to summary |
---|---|
public int getReferenceKind() Returns the reference kind of the cracked method handle, which in turn determines whether the method handle's underlying member was a constructor, method, or field. See the table above for definitions.
|
isVarArgs | back to summary |
---|---|
public default boolean isVarArgs() Determines if the underlying member was a variable arity method or constructor. Such members are represented by method handles that are varargs collectors. Implementation Specification This produces a result equivalent to:
|
referenceKindToString | back to summary |
---|---|
public static String referenceKindToString(int referenceKind) Returns the descriptive name of the given reference kind, as defined in the table above. The conventional prefix "REF_" is omitted.
|
reflectAs | back to summary |
---|---|
public <T extends Member> T reflectAs(Class<T> expected, MethodHandles. Reflects the underlying member as a method, constructor, or field object.
If the underlying member is public, it is reflected as if by
|
toString | back to summary |
---|---|
public static String toString(int kind, Class<?> defc, String name, MethodType type) Returns a string representation for a Implementation Specification This produces a result equivalent to:
|