public static class JavaConstant.Dynamic extends Object implements JavaConstant
JavaConstant.Dynamic, JavaConstant.MethodHandle, JavaConstant.MethodType, JavaConstant.Simple<T>, JavaConstant.Visitor<T>
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_NAME
The default name of a dynamic constant.
|
Constructor and Description |
---|
Dynamic(String name,
TypeDescription typeDescription,
JavaConstant.MethodHandle bootstrap,
List<JavaConstant> arguments)
Creates a dynamic resolved constant.
|
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.
|
static JavaConstant.Dynamic |
bootstrap(String name,
Constructor<?> constructor,
List<?> constants)
Binds the supplied bootstrap constructor for the resolution of a dynamic constant.
|
static JavaConstant.Dynamic |
bootstrap(String name,
Constructor<?> constructor,
Object... constant)
Binds the supplied bootstrap constructor for the resolution of a dynamic constant.
|
static JavaConstant.Dynamic |
bootstrap(String name,
MethodDescription.InDefinedShape bootstrap,
List<?> arguments)
Binds the supplied bootstrap method or constructor for the resolution of a dynamic constant.
|
static JavaConstant.Dynamic |
bootstrap(String name,
MethodDescription.InDefinedShape bootstrapMethod,
Object... constant)
Binds the supplied bootstrap method or constructor for the resolution of a dynamic constant.
|
static JavaConstant.Dynamic |
bootstrap(String name,
Method method,
List<?> constants)
Binds the supplied bootstrap method for the resolution of a dynamic constant.
|
static JavaConstant.Dynamic |
bootstrap(String name,
Method method,
Object... constant)
Binds the supplied bootstrap method for the resolution of a dynamic constant.
|
boolean |
equals(Object object) |
List<JavaConstant> |
getArguments()
Returns a list of the arguments to the dynamic constant.
|
JavaConstant.MethodHandle |
getBootstrap()
Returns a handle representation of the bootstrap method.
|
String |
getName()
Returns the name of the dynamic constant.
|
TypeDescription |
getTypeDescription()
Returns a description of the type of this constant.
|
int |
hashCode() |
static JavaConstant |
ofArrayVarHandle(Class<?> type)
Resolves a var handle constant for an array.
|
static JavaConstant |
ofArrayVarHandle(TypeDescription typeDescription)
Resolves a var handle constant for an array.
|
static JavaConstant.Dynamic |
ofAsm(TypePool typePool,
ConstantDynamic constantDynamic)
Resolves an ASM
ConstantDynamic to a JavaConstant.Dynamic . |
static JavaConstant |
ofEnumeration(Enum<?> enumeration)
Returns a
Enum value constant. |
static JavaConstant |
ofEnumeration(EnumerationDescription enumerationDescription)
Returns a
Enum value constant. |
static JavaConstant.Dynamic |
ofField(Field field)
Returns a
static , final field constant. |
static JavaConstant.Dynamic |
ofField(FieldDescription.InDefinedShape fieldDescription)
Returns a
static , final field constant. |
static JavaConstant.Dynamic |
ofInvocation(Constructor<?> constructor,
List<?> constants)
Represents a constant that is resolved by invoking a constructor.
|
static JavaConstant.Dynamic |
ofInvocation(Constructor<?> constructor,
Object... constant)
Represents a constant that is resolved by invoking a constructor.
|
static JavaConstant.Dynamic |
ofInvocation(MethodDescription.InDefinedShape methodDescription,
List<?> constants)
Represents a constant that is resolved by invoking a
static factory method or a constructor. |
static JavaConstant.Dynamic |
ofInvocation(MethodDescription.InDefinedShape methodDescription,
Object... constant)
Represents a constant that is resolved by invoking a
static factory method or a constructor. |
static JavaConstant.Dynamic |
ofInvocation(Method method,
List<?> constants)
Represents a constant that is resolved by invoking a
static factory method. |
static JavaConstant.Dynamic |
ofInvocation(Method method,
Object... constant)
Represents a constant that is resolved by invoking a
static factory method. |
static JavaConstant.Dynamic |
ofNullConstant()
Returns a constant
null value of type Object . |
static JavaConstant |
ofPrimitiveType(Class<?> type)
Returns a
Class constant for a primitive type. |
static JavaConstant |
ofPrimitiveType(TypeDescription typeDescription)
Returns a
Class constant for a primitive type. |
static JavaConstant |
ofVarHandle(Field field)
Resolves a var handle constant for a field.
|
static JavaConstant |
ofVarHandle(FieldDescription.InDefinedShape fieldDescription)
Resolves a var handle constant for a field.
|
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() |
JavaConstant |
withType(Class<?> type)
Resolves this
JavaConstant.Dynamic constant to resolve the returned instance to the supplied type. |
JavaConstant |
withType(TypeDescription typeDescription)
Resolves this
JavaConstant.Dynamic constant to resolve the returned instance to the supplied type. |
public static final String DEFAULT_NAME
public Dynamic(String name, TypeDescription typeDescription, JavaConstant.MethodHandle bootstrap, List<JavaConstant> arguments)
name
- The name of the dynamic constant.typeDescription
- A description of the represented value's type.bootstrap
- A handle representation of the bootstrap method.arguments
- A list of the arguments to the dynamic constant.public static JavaConstant.Dynamic ofAsm(TypePool typePool, ConstantDynamic constantDynamic)
ConstantDynamic
to a JavaConstant.Dynamic
.typePool
- The type pool to use for resolving type descriptions.constantDynamic
- The ASM constant to translate.JavaConstant
.public static JavaConstant.Dynamic ofNullConstant()
null
value of type Object
.public static JavaConstant ofPrimitiveType(Class<?> type)
Class
constant for a primitive type.type
- The primitive type to represent.public static JavaConstant ofPrimitiveType(TypeDescription typeDescription)
Class
constant for a primitive type.typeDescription
- The primitive type to represent.public static JavaConstant ofEnumeration(Enum<?> enumeration)
Enum
value constant.enumeration
- The enumeration value to represent.public static JavaConstant ofEnumeration(EnumerationDescription enumerationDescription)
Enum
value constant.enumerationDescription
- The enumeration value to represent.public static JavaConstant.Dynamic ofField(Field field)
static
, final
field constant.field
- The field to represent a value of.public static JavaConstant.Dynamic ofField(FieldDescription.InDefinedShape fieldDescription)
static
, final
field constant.fieldDescription
- The field to represent a value of.public static JavaConstant.Dynamic ofInvocation(Method method, Object... constant)
static
factory method.method
- The method to invoke to create the represented constant value.constant
- The method's constant arguments.public static JavaConstant.Dynamic ofInvocation(Method method, List<?> constants)
static
factory method.method
- The method to invoke to create the represented constant value.constants
- The constant values passed to the bootstrap method. Values can be represented either
as TypeDescription
, as JavaConstant
, as String
or a primitive
int
, long
, float
or double
represented as wrapper type.public static JavaConstant.Dynamic ofInvocation(Constructor<?> constructor, Object... constant)
constructor
- The constructor to invoke to create the represented constant value.constant
- The constant values passed to the bootstrap method. Values can be represented either
as TypeDescription
, as JavaConstant
, as String
or a primitive
int
, long
, float
or double
represented as wrapper type.public static JavaConstant.Dynamic ofInvocation(Constructor<?> constructor, List<?> constants)
constructor
- The constructor to invoke to create the represented constant value.constants
- The constant values passed to the bootstrap method. Values can be represented either
as TypeDescription
, as JavaConstant
, as String
or a primitive
int
, long
, float
or double
represented as wrapper type.public static JavaConstant.Dynamic ofInvocation(MethodDescription.InDefinedShape methodDescription, Object... constant)
static
factory method or a constructor.methodDescription
- The method or constructor to invoke to create the represented constant value.constant
- The constant values passed to the bootstrap method. Values can be represented either
as TypeDescription
, as JavaConstant
, as String
or a primitive
int
, long
, float
or double
represented as wrapper type.public static JavaConstant.Dynamic ofInvocation(MethodDescription.InDefinedShape methodDescription, List<?> constants)
static
factory method or a constructor.methodDescription
- The method or constructor to invoke to create the represented constant value.constants
- The constant values passed to the bootstrap method. Values can be represented either
as TypeDescription
, as JavaConstant
, as String
or a primitive
int
, long
, float
or double
represented as wrapper type.public static JavaConstant ofVarHandle(Field field)
field
- The field to represent a var handle for.public static JavaConstant ofVarHandle(FieldDescription.InDefinedShape fieldDescription)
fieldDescription
- The field to represent a var handle for.public static JavaConstant ofArrayVarHandle(Class<?> type)
type
- The array type for which the var handle is resolved.public static JavaConstant ofArrayVarHandle(TypeDescription typeDescription)
typeDescription
- The array type for which the var handle is resolved.public static JavaConstant.Dynamic bootstrap(String name, Method method, Object... constant)
name
- The name of the bootstrap constant that is provided to the bootstrap method or constructor.method
- The bootstrap method to invoke.constant
- The arguments for the bootstrap method represented as primitive wrapper types,
String
, TypeDescription
or JavaConstant
values or their loaded forms.public static JavaConstant.Dynamic bootstrap(String name, Method method, List<?> constants)
name
- The name of the bootstrap constant that is provided to the bootstrap method or constructor.method
- The bootstrap method to invoke.constants
- The constant values passed to the bootstrap method. Values can be represented either
as TypeDescription
, as JavaConstant
, as String
or a primitive
int
, long
, float
or double
represented as wrapper type.public static JavaConstant.Dynamic bootstrap(String name, Constructor<?> constructor, Object... constant)
name
- The name of the bootstrap constant that is provided to the bootstrap method or constructor.constructor
- The bootstrap constructor to invoke.constant
- The constant values passed to the bootstrap method. Values can be represented either
as TypeDescription
, as JavaConstant
, as String
or a primitive
int
, long
, float
or double
represented as wrapper type.public static JavaConstant.Dynamic bootstrap(String name, Constructor<?> constructor, List<?> constants)
name
- The name of the bootstrap constant that is provided to the bootstrap method or constructor.constructor
- The bootstrap constructor to invoke.constants
- The constant values passed to the bootstrap method. Values can be represented either
as TypeDescription
, as JavaConstant
, as String
or a primitive
int
, long
, float
or double
represented as wrapper type.public static JavaConstant.Dynamic bootstrap(String name, MethodDescription.InDefinedShape bootstrapMethod, Object... constant)
name
- The name of the bootstrap constant that is provided to the bootstrap method or constructor.bootstrapMethod
- The bootstrap method or constructor to invoke.constant
- The constant values passed to the bootstrap method. Values can be represented either
as TypeDescription
, as JavaConstant
, as String
or a primitive
int
, long
, float
or double
represented as wrapper type.public static JavaConstant.Dynamic bootstrap(String name, MethodDescription.InDefinedShape bootstrap, List<?> arguments)
name
- The name of the bootstrap constant that is provided to the bootstrap method or constructor.bootstrap
- The bootstrap method or constructor to invoke.arguments
- The constant values passed to the bootstrap method. Values can be represented either
as TypeDescription
, as JavaConstant
, as String
or a primitive
int
, long
, float
or double
represented as wrapper type.public String getName()
public JavaConstant.MethodHandle getBootstrap()
public List<JavaConstant> getArguments()
public JavaConstant withType(Class<?> type)
JavaConstant.Dynamic
constant to resolve the returned instance to the supplied type. The type must be a subtype of the
bootstrap method's return type. Constructors cannot be resolved to a different type.type
- The type to resolve the bootstrapped value to.public JavaConstant withType(TypeDescription typeDescription)
JavaConstant.Dynamic
constant to resolve the returned instance to the supplied type. The type must be a subtype of the
bootstrap method's return type. Constructors cannot be resolved to a different type.typeDescription
- The type to resolve the bootstrapped value to.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 boolean equals(@MaybeNull Object object)
Copyright © 2014–2025. All rights reserved.