public static class JavaConstant.MethodHandle extends Object implements JavaConstant
java.lang.invoke.MethodHandle
object. Note that constant MethodHandle
s cannot
be represented within the constant pool of a Java class and can therefore not be represented as an instance of
this representation order.Modifier and Type | Class and Description |
---|---|
static class |
JavaConstant.MethodHandle.HandleType
A representation of a method handle's type.
|
protected static interface |
JavaConstant.MethodHandle.MethodHandleInfo
A dispatcher to interact with
java.lang.invoke.MethodHandleInfo . |
protected static interface |
JavaConstant.MethodHandle.MethodHandles
A dispatcher to interact with
java.lang.invoke.MethodHandles . |
protected static interface |
JavaConstant.MethodHandle.MethodType
A dispatcher to interact with
java.lang.invoke.MethodType . |
JavaConstant.Dynamic, JavaConstant.MethodHandle, JavaConstant.Simple<T>, JavaConstant.Visitor<T>
Modifier and Type | Field and Description |
---|---|
protected static JavaConstant.MethodHandle.MethodHandleInfo |
METHOD_HANDLE_INFO
A dispatcher to interact with
java.lang.invoke.MethodHandleInfo . |
protected static JavaConstant.MethodHandle.MethodHandles |
METHOD_HANDLES
A dispatcher to interact with
java.lang.invoke.MethodHandles . |
protected static JavaConstant.MethodHandle.MethodHandles.Lookup |
METHOD_HANDLES_LOOKUP
A dispatcher to interact with
java.lang.invoke.MethodHandles$Lookup . |
protected static JavaConstant.MethodHandle.MethodType |
METHOD_TYPE
A dispatcher to interact with
java.lang.invoke.MethodType . |
Constructor and Description |
---|
MethodHandle(JavaConstant.MethodHandle.HandleType handleType,
TypeDescription ownerType,
String name,
TypeDescription returnType,
List<? extends TypeDescription> parameterTypes)
Creates a method handle representation.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
accept(JavaConstant.Visitor<T> visitor)
Applies the supplied visitor to this constant type with its respective callback.
|
boolean |
equals(Object other) |
String |
getDescriptor()
Returns the method descriptor of this method handle representation.
|
JavaConstant.MethodHandle.HandleType |
getHandleType()
Returns the handle type represented by this instance.
|
String |
getName()
Returns the name represented by this instance.
|
TypeDescription |
getOwnerType()
Returns the owner type of this instance.
|
TypeList |
getParameterTypes()
Returns the parameter types represented by this instance.
|
TypeDescription |
getReturnType()
Returns the return type represented by this instance.
|
TypeDescription |
getTypeDescription()
Returns a description of the type of this constant.
|
int |
hashCode() |
static Class<?> |
lookupType(Object callerClassLookup)
Returns the lookup type of the provided
java.lang.invoke.MethodHandles$Lookup instance. |
static JavaConstant.MethodHandle |
of(Constructor<?> constructor)
Creates a method handle representation of the given constructor.
|
static JavaConstant.MethodHandle |
of(Method method)
Creates a method handle representation of the given method.
|
static JavaConstant.MethodHandle |
of(MethodDescription.InDefinedShape methodDescription)
Creates a method handle representation of the given method.
|
static JavaConstant.MethodHandle |
ofGetter(Field field)
Returns a method handle for a setter of the given field.
|
static JavaConstant.MethodHandle |
ofGetter(FieldDescription.InDefinedShape fieldDescription)
Returns a method handle for a setter of the given field.
|
static JavaConstant.MethodHandle |
ofLoaded(Object methodHandle)
Creates a method handles representation of a loaded method handle which is analyzed using a public
MethodHandles.Lookup object. |
static JavaConstant.MethodHandle |
ofLoaded(Object methodHandle,
Object lookup)
Creates a method handles representation of a loaded method handle which is analyzed using the given lookup context.
|
static JavaConstant.MethodHandle |
ofSetter(Field field)
Returns a method handle for a getter of the given field.
|
static JavaConstant.MethodHandle |
ofSetter(FieldDescription.InDefinedShape fieldDescription)
Returns a method handle for a getter of the given field.
|
static JavaConstant.MethodHandle |
ofSpecial(Method method,
Class<?> type)
Creates a method handle representation of the given method for an explicit special method invocation of an otherwise virtual method.
|
static JavaConstant.MethodHandle |
ofSpecial(MethodDescription.InDefinedShape methodDescription,
TypeDescription typeDescription)
Creates a method handle representation of the given method for an explicit special method invocation of an otherwise virtual method.
|
Object |
toDescription()
Returns this constant as a Java
java.lang.constant.ConstantDesc if the current VM is of at least version 12. |
StackManipulation |
toStackManipulation()
Returns a stack manipulation loading this value.
|
String |
toString() |
protected static final JavaConstant.MethodHandle.MethodHandleInfo METHOD_HANDLE_INFO
java.lang.invoke.MethodHandleInfo
.protected static final JavaConstant.MethodHandle.MethodType METHOD_TYPE
java.lang.invoke.MethodType
.protected static final JavaConstant.MethodHandle.MethodHandles METHOD_HANDLES
java.lang.invoke.MethodHandles
.protected static final JavaConstant.MethodHandle.MethodHandles.Lookup METHOD_HANDLES_LOOKUP
java.lang.invoke.MethodHandles$Lookup
.public MethodHandle(JavaConstant.MethodHandle.HandleType handleType, TypeDescription ownerType, String name, TypeDescription returnType, List<? extends TypeDescription> parameterTypes)
handleType
- The handle type that is represented by this instance.ownerType
- The owner type that is represented by this instance.name
- The name that is represented by this instance.returnType
- The return type that is represented by this instance.parameterTypes
- The parameter types that is represented by this instance.public static JavaConstant.MethodHandle ofLoaded(Object methodHandle)
MethodHandles.Lookup
object.
A method handle can only be analyzed on virtual machines that support the corresponding API (Java 7+). For virtual machines before Java 8+,
a method handle instance can only be analyzed by taking advantage of private APIs what might require a access context.methodHandle
- The loaded method handle to represent.public static JavaConstant.MethodHandle ofLoaded(Object methodHandle, Object lookup)
methodHandle
- The loaded method handle to represent.lookup
- The lookup object to use for analyzing the method handle.public static JavaConstant.MethodHandle of(Method method)
method
- The method ro represent.public static JavaConstant.MethodHandle of(Constructor<?> constructor)
constructor
- The constructor ro represent.public static JavaConstant.MethodHandle of(MethodDescription.InDefinedShape methodDescription)
methodDescription
- The method ro represent.public static JavaConstant.MethodHandle ofSpecial(Method method, Class<?> type)
method
- The method ro represent.type
- The type on which the method is to be invoked on as a special method invocation.public static JavaConstant.MethodHandle ofSpecial(MethodDescription.InDefinedShape methodDescription, TypeDescription typeDescription)
methodDescription
- The method ro represent.typeDescription
- The type on which the method is to be invoked on as a special method invocation.public static JavaConstant.MethodHandle ofGetter(Field field)
field
- The field to represent.public static JavaConstant.MethodHandle ofGetter(FieldDescription.InDefinedShape fieldDescription)
fieldDescription
- The field to represent.public static JavaConstant.MethodHandle ofSetter(Field field)
field
- The field to represent.public static JavaConstant.MethodHandle ofSetter(FieldDescription.InDefinedShape fieldDescription)
fieldDescription
- The field to represent.public static Class<?> lookupType(Object callerClassLookup)
java.lang.invoke.MethodHandles$Lookup
instance.callerClassLookup
- An instance of java.lang.invoke.MethodHandles$Lookup
.public Object toDescription()
java.lang.constant.ConstantDesc
if the current VM is of at least version 12.
If the current VM is of an older version and does not support the type, an exception is thrown.toDescription
in interface JavaConstant
java.lang.constant.ConstantDesc
.public <T> T accept(JavaConstant.Visitor<T> visitor)
accept
in interface JavaConstant
T
- The type of the value that is returned by the visitor.visitor
- The visitor to dispatch.public TypeDescription getTypeDescription()
getTypeDescription
in interface ConstantValue
public StackManipulation toStackManipulation()
toStackManipulation
in interface ConstantValue
public JavaConstant.MethodHandle.HandleType getHandleType()
public TypeDescription getOwnerType()
public String getName()
public TypeDescription getReturnType()
public TypeList getParameterTypes()
public String getDescriptor()
public boolean equals(@MaybeNull Object other)
Copyright © 2014–2025. All rights reserved.