- java.lang.Object
-
- java.lang.constant.DynamicConstantDesc<T>
-
- Type Parameters:
T
- the type of the dynamic constant
- All Implemented Interfaces:
ConstantDesc
- Direct Known Subclasses:
Enum.EnumDesc
,VarHandle.VarHandleDesc
public abstract class DynamicConstantDesc<T> extends Object implements ConstantDesc
A nominal descriptor for a dynamic constant (one described in the constant pool withConstant_Dynamic_info
.)Concrete subtypes of DynamicConstantDesc must be value-based.
- Since:
- 12
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DynamicConstantDesc(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc... bootstrapArgs)
Creates a nominal descriptor for a dynamic constant.
-
Method Summary
Modifier and Type Method Description ConstantDesc[]
bootstrapArgs()
Returns the bootstrap arguments for this constant.List<ConstantDesc>
bootstrapArgsList()
Returns the bootstrap arguments for this constant as an immutableList
.DirectMethodHandleDesc
bootstrapMethod()
Returns aMethodHandleDesc
describing the bootstrap method for this constant.String
constantName()
Returns the name that would appear in theNameAndType
operand of theLDC
for this constant.ClassDesc
constantType()
Returns aClassDesc
describing the type that would appear in theNameAndType
operand of theLDC
for this constant.boolean
equals(Object o)
Compares the specified object with this descriptor for equality.static <T> DynamicConstantDesc<T>
of(DirectMethodHandleDesc bootstrapMethod)
Returns a nominal descriptor for a dynamic constant whose bootstrap has no static arguments, whose name parameter isConstantDescs.DEFAULT_NAME
, and whose type parameter is always the same as the bootstrap method return type.static <T> DynamicConstantDesc<T>
of(DirectMethodHandleDesc bootstrapMethod, ConstantDesc... bootstrapArgs)
Returns a nominal descriptor for a dynamic constant whose name parameter isConstantDescs.DEFAULT_NAME
, and whose type parameter is always the same as the bootstrap method return type.static <T> ConstantDesc
ofCanonical(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc[] bootstrapArgs)
Returns a nominal descriptor for a dynamic constant, transforming it into a more specific type if the constant bootstrap is a well-known one and a more specific nominal descriptor type (e.g., ClassDesc) is available.static <T> DynamicConstantDesc<T>
ofNamed(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc... bootstrapArgs)
Returns a nominal descriptor for a dynamic constant.String
toString()
Returns a compact textual description of this constant description, including the bootstrap method, the constant name and type, and the static bootstrap arguments.-
Methods declared in class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods declared in interface java.lang.constant.ConstantDesc
resolveConstantDesc
-
-
-
-
Constructor Detail
-
DynamicConstantDesc
protected DynamicConstantDesc(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc... bootstrapArgs)
Creates a nominal descriptor for a dynamic constant.- Parameters:
bootstrapMethod
- aDirectMethodHandleDesc
describing the bootstrap method for the constantconstantName
- The unqualified name that would appear in theNameAndType
operand of theLDC
for this constantconstantType
- aClassDesc
describing the type that would appear in theNameAndType
operand of theLDC
for this constantbootstrapArgs
-ConstantDesc
s describing the static arguments to the bootstrap, that would appear in theBootstrapMethods
attribute- Throws:
NullPointerException
- if any argument is nullIllegalArgumentException
- if thename
has the incorrect format- See The Java™ Virtual Machine Specification:
- 4.2.2 Unqualified Names
-
-
Method Detail
-
ofCanonical
public static <T> ConstantDesc ofCanonical(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc[] bootstrapArgs)
Returns a nominal descriptor for a dynamic constant, transforming it into a more specific type if the constant bootstrap is a well-known one and a more specific nominal descriptor type (e.g., ClassDesc) is available.Classes whose
Constable.describeConstable()
method produce a DynamicConstantDesc with a well-known bootstrap includingClass
(for instances describing primitive types),Enum
, andVarHandle
.Bytecode-reading APIs that process the constant pool and wish to expose entries as
ConstantDesc
to their callers should generally use this method in preference toofNamed(DirectMethodHandleDesc, String, ClassDesc, ConstantDesc...)
because this may result in a more specific type that can be provided to callers.- Type Parameters:
T
- the type of the dynamic constant- Parameters:
bootstrapMethod
- aDirectMethodHandleDesc
describing the bootstrap method for the constantconstantName
- The unqualified name that would appear in theNameAndType
operand of theLDC
for this constantconstantType
- aClassDesc
describing the type that would appear in theNameAndType
operand of theLDC
for this constantbootstrapArgs
-ConstantDesc
s describing the static arguments to the bootstrap, that would appear in theBootstrapMethods
attribute- Returns:
- the nominal descriptor
- Throws:
NullPointerException
- if any argument is nullIllegalArgumentException
- if thename
has the incorrect format- See The Java™ Virtual Machine Specification:
- 4.2.2 Unqualified Names
-
ofNamed
public static <T> DynamicConstantDesc<T> ofNamed(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc... bootstrapArgs)
Returns a nominal descriptor for a dynamic constant.- Type Parameters:
T
- the type of the dynamic constant- Parameters:
bootstrapMethod
- aDirectMethodHandleDesc
describing the bootstrap method for the constantconstantName
- The unqualified name that would appear in theNameAndType
operand of theLDC
for this constantconstantType
- aClassDesc
describing the type that would appear in theNameAndType
operand of theLDC
for this constantbootstrapArgs
-ConstantDesc
s describing the static arguments to the bootstrap, that would appear in theBootstrapMethods
attribute- Returns:
- the nominal descriptor
- Throws:
NullPointerException
- if any argument is nullIllegalArgumentException
- if thename
has the incorrect format- See The Java™ Virtual Machine Specification:
- 4.2.2 Unqualified Names
-
of
public static <T> DynamicConstantDesc<T> of(DirectMethodHandleDesc bootstrapMethod, ConstantDesc... bootstrapArgs)
Returns a nominal descriptor for a dynamic constant whose name parameter isConstantDescs.DEFAULT_NAME
, and whose type parameter is always the same as the bootstrap method return type.- Type Parameters:
T
- the type of the dynamic constant- Parameters:
bootstrapMethod
- aDirectMethodHandleDesc
describing the bootstrap method for the constantbootstrapArgs
-ConstantDesc
s describing the static arguments to the bootstrap, that would appear in theBootstrapMethods
attribute- Returns:
- the nominal descriptor
- Throws:
NullPointerException
- if any argument is null- See The Java™ Virtual Machine Specification:
- 4.2.2 Unqualified Names
-
of
public static <T> DynamicConstantDesc<T> of(DirectMethodHandleDesc bootstrapMethod)
Returns a nominal descriptor for a dynamic constant whose bootstrap has no static arguments, whose name parameter isConstantDescs.DEFAULT_NAME
, and whose type parameter is always the same as the bootstrap method return type.- Type Parameters:
T
- the type of the dynamic constant- Parameters:
bootstrapMethod
- aDirectMethodHandleDesc
describing the bootstrap method for the constant- Returns:
- the nominal descriptor
- Throws:
NullPointerException
- if any argument is null
-
constantName
public String constantName()
Returns the name that would appear in theNameAndType
operand of theLDC
for this constant.- Returns:
- the constant name
-
constantType
public ClassDesc constantType()
Returns aClassDesc
describing the type that would appear in theNameAndType
operand of theLDC
for this constant.- Returns:
- the constant type
-
bootstrapMethod
public DirectMethodHandleDesc bootstrapMethod()
Returns aMethodHandleDesc
describing the bootstrap method for this constant.- Returns:
- the bootstrap method
-
bootstrapArgs
public ConstantDesc[] bootstrapArgs()
Returns the bootstrap arguments for this constant.- Returns:
- the bootstrap arguments
-
bootstrapArgsList
public List<ConstantDesc> bootstrapArgsList()
Returns the bootstrap arguments for this constant as an immutableList
.- Returns:
- a
List
of the bootstrap arguments
-
equals
public final boolean equals(Object o)
Compares the specified object with this descriptor for equality. Returnstrue
if and only if the specified object is also a DynamicConstantDesc, and both descriptors have equal bootstrap methods, bootstrap argument lists, constant name, and constant type.- Overrides:
equals
in classObject
- Parameters:
o
- theDynamicConstantDesc
to compare to thisDynamicConstantDesc
- Returns:
true
if the specifiedDynamicConstantDesc
is equals to thisDynamicConstantDesc
.- See Also:
Object.hashCode()
,HashMap
-
toString
public String toString()
Returns a compact textual description of this constant description, including the bootstrap method, the constant name and type, and the static bootstrap arguments.
-
-