- All Superinterfaces:
ConstantDesc
- All Known Subinterfaces:
DirectMethodHandleDesc
public interface MethodHandleDesc extends ConstantDesc
MethodHandle constant.- API Note:
- In the future, if the Java language permits, MethodHandleDesc
may become a
sealedinterface, which would prohibit subclassing except by explicitly permitted types. Non-platform classes should not implement MethodHandleDesc directly. - Since:
- 12
-
Method Summary
Modifier and Type Method Description default MethodHandleDescasType(MethodTypeDesc type)Returns a MethodHandleDesc that describes this method handle adapted to a different type, as if byMethodHandle.asType(MethodType).booleanequals(Object o)Compares the specified object with this descriptor for equality.MethodTypeDescinvocationType()Returns aMethodTypeDescdescribing the invocation type of the method handle described by this nominal descriptor.static DirectMethodHandleDescof(DirectMethodHandleDesc.Kind kind, ClassDesc owner, String name, String lookupDescriptor)Creates a MethodHandleDesc corresponding to an invocation of a declared method, invocation of a constructor, or access to a field.static DirectMethodHandleDescofConstructor(ClassDesc owner, ClassDesc... paramTypes)Returns a MethodHandleDesc corresponding to invocation of a constructorstatic DirectMethodHandleDescofField(DirectMethodHandleDesc.Kind kind, ClassDesc owner, String fieldName, ClassDesc fieldType)Creates a MethodHandleDesc corresponding to a method handle that accesses a field.static DirectMethodHandleDescofMethod(DirectMethodHandleDesc.Kind kind, ClassDesc owner, String name, MethodTypeDesc lookupMethodType)Creates a MethodHandleDesc corresponding to an invocation of a declared method or constructor.
-
Method Details
-
of
static DirectMethodHandleDesc of(DirectMethodHandleDesc.Kind kind, ClassDesc owner, String name, String lookupDescriptor)Creates a MethodHandleDesc corresponding to an invocation of a declared method, invocation of a constructor, or access to a field.The lookup descriptor string has the same format as for the various variants of
CONSTANT_MethodHandle_infoand for the lookup methods onMethodHandles.Lookup. For a method or constructor invocation, it is interpreted as a method type descriptor; for field access, it is interpreted as a field descriptor. IfkindisCONSTRUCTOR, thenameparameter is ignored and the return type of the lookup descriptor must bevoid. Ifkindcorresponds to a virtual method invocation, the lookup type includes the method parameters but not the receiver type.- Parameters:
kind- The kind of method handle to be describedowner- aClassDescdescribing the class containing the method, constructor, or fieldname- the unqualified name of the method or field (ignored ifkindisCONSTRUCTOR)lookupDescriptor- a method descriptor string the lookup type, if the request is for a method invocation, or describing the invocation type, if the request is for a field or constructor- Returns:
- the MethodHandleDesc
- Throws:
NullPointerException- if any of the non-ignored arguments are nullIllegalArgumentException- if the descriptor string is not a valid method or field descriptor- See Java Virtual Machine Specification:
-
4.4.8 The CONSTANT_MethodHandle_info Structure
4.2.2 Unqualified Names
4.3.2 Field Descriptors
4.3.3 Method Descriptors
-
ofMethod
static DirectMethodHandleDesc ofMethod(DirectMethodHandleDesc.Kind kind, ClassDesc owner, String name, MethodTypeDesc lookupMethodType)Creates a MethodHandleDesc corresponding to an invocation of a declared method or constructor.The lookup descriptor string has the same format as for the lookup methods on
MethodHandles.Lookup. IfkindisCONSTRUCTOR, the name is ignored and the return type of the lookup type must bevoid. Ifkindcorresponds to a virtual method invocation, the lookup type includes the method parameters but not the receiver type.- Parameters:
kind- The kind of method handle to be described; must be one ofSPECIAL, VIRTUAL, STATIC, INTERFACE_SPECIAL, INTERFACE_VIRTUAL, INTERFACE_STATIC, CONSTRUCTORowner- aClassDescdescribing the class containing the method or constructorname- the unqualified name of the method (ignored ifkindisCONSTRUCTOR)lookupMethodType- aMethodTypeDescdescribing the lookup type- Returns:
- the MethodHandleDesc
- Throws:
NullPointerException- if any non-ignored arguments are nullIllegalArgumentException- if thenamehas the incorrect format, or the kind is invalid- See Java Virtual Machine Specification:
-
4.2.2 Unqualified Names
-
ofField
static DirectMethodHandleDesc ofField(DirectMethodHandleDesc.Kind kind, ClassDesc owner, String fieldName, ClassDesc fieldType)Creates a MethodHandleDesc corresponding to a method handle that accesses a field.- Parameters:
kind- the kind of the method handle to be described; must be one ofGETTER,SETTER,STATIC_GETTER, orSTATIC_SETTERowner- aClassDescdescribing the class containing the fieldfieldName- the unqualified name of the fieldfieldType- aClassDescdescribing the type of the field- Returns:
- the MethodHandleDesc
- Throws:
NullPointerException- if any of the arguments are nullIllegalArgumentException- if thekindis not one of the valid values or if the field name is not valid- See Java Virtual Machine Specification:
-
4.2.2 Unqualified Names
-
ofConstructor
Returns a MethodHandleDesc corresponding to invocation of a constructor- Parameters:
owner- aClassDescdescribing the class containing the constructorparamTypes-ClassDescs describing the parameter types of the constructor- Returns:
- the MethodHandleDesc
- Throws:
NullPointerException- if any argument or its contents isnull
-
asType
Returns a MethodHandleDesc that describes this method handle adapted to a different type, as if byMethodHandle.asType(MethodType).- Parameters:
type- aMethodHandleDescdescribing the new method type- Returns:
- a MethodHandleDesc for the adapted method handle
- Throws:
NullPointerException- if the argument isnull
-
invocationType
MethodTypeDesc invocationType()Returns aMethodTypeDescdescribing the invocation type of the method handle described by this nominal descriptor. The invocation type describes the full set of stack values that are consumed by the invocation (including the receiver, if any).- Returns:
- a MethodHandleDesc describing the method handle type
-
equals
Compares the specified object with this descriptor for equality. Returnstrueif and only if the specified object is also a MethodHandleDesc, and both encode the same nominal description of a method handle.- Overrides:
equalsin classObject- Parameters:
o- the other object- Returns:
- whether this descriptor is equal to the other object
- See Also:
Object.hashCode(),HashMap
-