-
public interface MethodHandleInfo
A reference to a cracked MethodHandle, which allows access to its symbolic parts. Call Lookup.revealDirect to crack a MethodHandle.- Since:
- 1.8
-
-
Field Summary
Fields Modifier and Type Field Description static int
REF_getField
Getter MethodHandle for an instance fieldstatic int
REF_getStatic
Getter MethodHandle for an static fieldstatic int
REF_invokeInterface
MethodHandle for an interface methodstatic int
REF_invokeSpecial
MethodHandle for an special methodstatic int
REF_invokeStatic
MethodHandle for a static methodstatic int
REF_invokeVirtual
MethodHandle for an instance methodstatic int
REF_newInvokeSpecial
MethodHandle for a constructorstatic int
REF_putField
Setter MethodHandle for an instance fieldstatic int
REF_putStatic
Setter MethodHandle for an static field
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Class<?>
getDeclaringClass()
Returns the Class where the cracked MethodHandle's underlying method, field or constructor is declared.MethodType
getMethodType()
Returns the type of the MethodHandle's underlying member as a MethodType.int
getModifiers()
Returns the modifiers of the MethodHandle's underlying member.String
getName()
Returns the simple name of the MethodHandle's underlying member.int
getReferenceKind()
Returns the reference kind of the MethodHandle.default boolean
isVarArgs()
Returns whether the MethodHandle's underlying method or constructor has variable argument arity.static String
referenceKindToString(int referenceKind)
Returns a string representing the equivalent bytecode for the referenceKind.<T extends Member>
TreflectAs(Class<T> expected, MethodHandles.Lookup lookup)
Reflects the underlying member as a Method, Field or Constructor.static String
toString(int kind, Class<?> defc, String name, MethodType type)
Answers a string containing a concise, human-readable description of the receiver.
-
-
-
Field Detail
-
REF_getField
static final int REF_getField
Getter MethodHandle for an instance field- See Also:
- Constant Field Values
-
REF_getStatic
static final int REF_getStatic
Getter MethodHandle for an static field- See Also:
- Constant Field Values
-
REF_putField
static final int REF_putField
Setter MethodHandle for an instance field- See Also:
- Constant Field Values
-
REF_putStatic
static final int REF_putStatic
Setter MethodHandle for an static field- See Also:
- Constant Field Values
-
REF_invokeVirtual
static final int REF_invokeVirtual
MethodHandle for an instance method- See Also:
- Constant Field Values
-
REF_invokeStatic
static final int REF_invokeStatic
MethodHandle for a static method- See Also:
- Constant Field Values
-
REF_invokeSpecial
static final int REF_invokeSpecial
MethodHandle for an special method- See Also:
- Constant Field Values
-
REF_newInvokeSpecial
static final int REF_newInvokeSpecial
MethodHandle for a constructor- See Also:
- Constant Field Values
-
REF_invokeInterface
static final int REF_invokeInterface
MethodHandle for an interface method- See Also:
- Constant Field Values
-
-
Method Detail
-
getDeclaringClass
Class<?> getDeclaringClass()
Returns the Class where the cracked MethodHandle's underlying method, field or constructor is declared.- Returns:
- class that declares the underlying member
-
getName
String getName()
Returns the simple name of the MethodHandle's underlying member.- Returns:
- A string representing the name of the method or field, or "<init>" for constructor.
-
getMethodType
MethodType getMethodType()
Returns the type of the MethodHandle's underlying member as a MethodType. If the underlying member is non-static, the receiver parameter will not be included. If the underlying member is field getter, the MethodType will take no parameters, and the return type will be the field type. If the underlying member is field setter, the MethodType will take one parameter of the field type, and the return type will be void.- Returns:
- A MethodType object representing the signature of the method or field
-
getModifiers
int getModifiers()
Returns the modifiers of the MethodHandle's underlying member.- Returns:
- An int representing the member's modifiers, or -1 if the underlying member is not accessible.
-
getReferenceKind
int getReferenceKind()
Returns the reference kind of the MethodHandle. The possible reference kinds are the declared MethodHandleInfo.REF fields.- Returns:
- Returns one of the defined reference kinds which represent the MethodHandle kind.
-
isVarArgs
default boolean isVarArgs()
Returns whether the MethodHandle's underlying method or constructor has variable argument arity.- Returns:
- whether the underlying method has variable arity
-
reflectAs
<T extends Member> T reflectAs(Class<T> expected, MethodHandles.Lookup lookup)
Reflects the underlying member as a Method, Field or Constructor. The member must be accessible to the provided lookup object. Public members are reflected as if bygetMethod
,getField
orgetConstructor
. Non-public members are reflected as if bygetDeclaredMethod
,getDeclaredField
orgetDeclaredConstructor
.- Type Parameters:
T
- The expected type of the returned Member- Parameters:
expected
- The expected Class of the returned Memberlookup
- The lookup that was used to create the MethodHandle, or a lookup object with equivalent access- Returns:
- A Method, Field or Constructor representing the underlying member of the MethodHandle
- Throws:
NullPointerException
- If either argument is nullIllegalArgumentException
- If the underlying member is not accessible to the provided lookup objectClassCastException
- If the underlying member is not of the expected type
-
referenceKindToString
static String referenceKindToString(int referenceKind) throws IllegalArgumentException
Returns a string representing the equivalent bytecode for the referenceKind.- Parameters:
referenceKind
- The referenceKind to lookup- Returns:
- a String representing the equivalent bytecode
- Throws:
IllegalArgumentException
- If the provided referenceKind is invalid
-
toString
static String toString(int kind, Class<?> defc, String name, MethodType type)
Answers a string containing a concise, human-readable description of the receiver.- Parameters:
kind
- the reference kind, one of the declared MethodHandleInfo.REF fields.defc
- the class where the member is declaredname
- the name of the membertype
- the member's MethodType- Returns:
- a String of the format "K C.N:MT"
-
-