Top Description Methods
java.lang.constant

public sealed Interface MethodHandleDesc

extends ConstantDesc
Known Direct Subinterfaces
java.lang.constant.DirectMethodHandleDesc
Known Direct Implementers
java.lang.constant.AsTypeMethodHandleDesc
Imports
java.lang.invoke.MethodHandle, .MethodHandles, .MethodType, jdk.internal.constant.DirectMethodHandleDescImpl

A nominal descriptor for a MethodHandle constant.
Since
12

Method Summary

Modifier and TypeMethod and Description
public default MethodHandleDesc

Returns:

a MethodHandleDesc for the adapted method handle
asType
(MethodTypeDesc
a MethodHandleDesc describing the new method type
type
)

Returns a MethodHandleDesc that describes this method handle adapted to a different type, as if by MethodHandle#asType(MethodType).

public boolean

Returns:

whether this descriptor is equal to the other object
equals
(Object
the other object
o
)

Compares the specified object with this descriptor for equality.

public MethodTypeDesc

Returns:

a MethodHandleDesc describing the method handle type
invocationType
()

Returns a MethodTypeDesc describing the invocation type of the method handle described by this nominal descriptor.

public static DirectMethodHandleDesc

Returns:

the MethodHandleDesc
of
(DirectMethodHandleDesc.Kind
The kind of method handle to be described
kind
,
ClassDesc
a ClassDesc describing the class containing the method, constructor, or field
owner
,
String
the unqualified name of the method or field (ignored if kind is CONSTRUCTOR)
name
,
String
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
lookupDescriptor
)

Creates a MethodHandleDesc corresponding to an invocation of a declared method, invocation of a constructor, or access to a field.

public static DirectMethodHandleDesc

Returns:

the MethodHandleDesc
ofConstructor
(ClassDesc
a ClassDesc describing the class containing the constructor
owner
,
ClassDesc...
ClassDescs describing the parameter types of the constructor
paramTypes
)

Returns a MethodHandleDesc corresponding to invocation of a constructor

public static DirectMethodHandleDesc

Returns:

the MethodHandleDesc
ofField
(DirectMethodHandleDesc.Kind
the kind of the method handle to be described; must be one of GETTER, SETTER, STATIC_GETTER, or STATIC_SETTER
kind
,
ClassDesc
a ClassDesc describing the class containing the field
owner
,
String
the unqualified name of the field
fieldName
,
ClassDesc
a ClassDesc describing the type of the field
fieldType
)

Creates a MethodHandleDesc corresponding to a method handle that accesses a field.

public static DirectMethodHandleDesc

Returns:

the MethodHandleDesc
ofMethod
(DirectMethodHandleDesc.Kind
The kind of method handle to be described; must be one of SPECIAL, VIRTUAL, STATIC, INTERFACE_SPECIAL, INTERFACE_VIRTUAL, INTERFACE_STATIC, CONSTRUCTOR
kind
,
ClassDesc
a ClassDesc describing the class containing the method or constructor
owner
,
String
the unqualified name of the method (ignored if kind is CONSTRUCTOR)
name
,
MethodTypeDesc
a MethodTypeDesc describing the lookup type
lookupMethodType
)

Creates a MethodHandleDesc corresponding to an invocation of a declared method or constructor.

public MethodHandle
resolveConstantDesc(MethodHandles.Lookup
The MethodHandles.Lookup to provide name resolution and access control context
lookup
)

Redeclares java.lang.constant.ConstantDesc.resolveConstantDesc.

Resolves this descriptor reflectively, emulating the resolution behavior of JVMS 5.4.3 and the access control behavior of JVMS 5.4.4.

Method Detail

asTypeback to summary
public default MethodHandleDesc asType(MethodTypeDesc type)

Returns a MethodHandleDesc that describes this method handle adapted to a different type, as if by MethodHandle#asType(MethodType).

Parameters
type:MethodTypeDesc

a MethodHandleDesc describing the new method type

Returns:MethodHandleDesc

a MethodHandleDesc for the adapted method handle

Exceptions
NullPointerException:
if the argument is null
equalsback to summary
public boolean equals(Object o)

Compares the specified object with this descriptor for equality. Returns true if and only if the specified object is also a MethodHandleDesc, and both encode the same nominal description of a method handle.

Parameters
o:Object

the other object

Returns:boolean

whether this descriptor is equal to the other object

invocationTypeback to summary
public MethodTypeDesc invocationType()

Returns a MethodTypeDesc describing 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:MethodTypeDesc

a MethodHandleDesc describing the method handle type

ofback to summary
public 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_info and for the lookup methods on MethodHandles.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. If kind is CONSTRUCTOR, the name parameter is ignored and the return type of the lookup descriptor must be void. If kind corresponds to a virtual method invocation, the lookup type includes the method parameters but not the receiver type.

Parameters
kind:DirectMethodHandleDesc.Kind

The kind of method handle to be described

owner:ClassDesc

a ClassDesc describing the class containing the method, constructor, or field

name:String

the unqualified name of the method or field (ignored if kind is CONSTRUCTOR)

lookupDescriptor:String

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:DirectMethodHandleDesc

the MethodHandleDesc

Exceptions
NullPointerException:
if any of the non-ignored arguments are null
IllegalArgumentException:
if the descriptor string is not a valid method or field descriptor
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
ofConstructorback to summary
public static DirectMethodHandleDesc ofConstructor(ClassDesc owner, ClassDesc... paramTypes)

Returns a MethodHandleDesc corresponding to invocation of a constructor

Parameters
owner:ClassDesc

a ClassDesc describing the class containing the constructor

paramTypes:ClassDesc[]

ClassDescs describing the parameter types of the constructor

Returns:DirectMethodHandleDesc

the MethodHandleDesc

Exceptions
NullPointerException:
if any argument or its contents is null
ofFieldback to summary
public 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:DirectMethodHandleDesc.Kind

the kind of the method handle to be described; must be one of GETTER, SETTER, STATIC_GETTER, or STATIC_SETTER

owner:ClassDesc

a ClassDesc describing the class containing the field

fieldName:String

the unqualified name of the field

fieldType:ClassDesc

a ClassDesc describing the type of the field

Returns:DirectMethodHandleDesc

the MethodHandleDesc

Exceptions
NullPointerException:
if any of the arguments are null
IllegalArgumentException:
if the kind is not one of the valid values or if the field name is not valid
Java Virtual Machine Specification
4.2.2 Unqualified Names
ofMethodback to summary
public 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. If kind is CONSTRUCTOR, the name is ignored and the return type of the lookup type must be void. If kind corresponds to a virtual method invocation, the lookup type includes the method parameters but not the receiver type.

Parameters
kind:DirectMethodHandleDesc.Kind

The kind of method handle to be described; must be one of SPECIAL, VIRTUAL, STATIC, INTERFACE_SPECIAL, INTERFACE_VIRTUAL, INTERFACE_STATIC, CONSTRUCTOR

owner:ClassDesc

a ClassDesc describing the class containing the method or constructor

name:String

the unqualified name of the method (ignored if kind is CONSTRUCTOR)

lookupMethodType:MethodTypeDesc

a MethodTypeDesc describing the lookup type

Returns:DirectMethodHandleDesc

the MethodHandleDesc

Exceptions
NullPointerException:
if any non-ignored arguments are null
IllegalArgumentException:
if the name has the incorrect format, or the kind is invalid
Java Virtual Machine Specification
4.2.2 Unqualified Names
resolveConstantDescback to summary
public MethodHandle resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException

Redeclares java.lang.constant.ConstantDesc.resolveConstantDesc.

Doc from java.lang.constant.ConstantDesc.resolveConstantDesc.

Resolves this descriptor reflectively, emulating the resolution behavior of JVMS 5.4.3 and the access control behavior of JVMS 5.4.4. The resolution and access control context is provided by the MethodHandles.Lookup parameter. No caching of the resulting value is performed.

Parameters
lookup:MethodHandles.Lookup

The MethodHandles.Lookup to provide name resolution and access control context

Returns:MethodHandle

the resolved constant value

Annotations
@Override
Exceptions
ReflectiveOperationException:
if a class, method, or field could not be reflectively resolved in the course of resolution