Top Description Methods
java.lang.constant

public sealed Interface ConstantDesc

Known Direct Subinterfaces
java.lang.constant.MethodHandleDesc, java.lang.constant.MethodTypeDesc, java.lang.constant.ClassDesc
Known Direct Implementers
java.lang.constant.DynamicConstantDesc, java.lang.Double, java.lang.Float, java.lang.Integer, java.lang.Long, java.lang.String
Imports
java.lang.Enum.EnumDesc, java.lang.invoke.MethodHandle, .MethodHandles, .MethodType, .VarHandle.VarHandleDesc

A nominal descriptor for a loadable constant value, as defined in JVMS 4.4. Such a descriptor can be resolved via ConstantDesc#resolveConstantDesc(MethodHandles.Lookup) to yield the constant value itself.

Class names in a nominal descriptor, like class names in the constant pool of a classfile, must be interpreted with respect to a particular class loader, which is not part of the nominal descriptor.

Static constants that are expressible natively in the constant pool (String, Integer, Long, Float, and Double) implement ConstantDesc, and serve as nominal descriptors for themselves. Native linkable constants (Class, MethodType, and MethodHandle) have counterpart ConstantDesc types: ClassDesc, MethodTypeDesc, and MethodHandleDesc. Other constants are represented by subtypes of DynamicConstantDesc.

APIs that perform generation or parsing of bytecode are encouraged to use ConstantDesc to describe the operand of an ldc instruction (including dynamic constants), the static bootstrap arguments of dynamic constants and invokedynamic instructions, and other bytecodes or classfile structures that make use of the constant pool.

Constants describing various common constants (such as ClassDesc instances for platform types) can be found in ConstantDescs.

Implementations of ConstantDesc should be immutable and their behavior should not rely on object identity.

Non-platform classes should not implement ConstantDesc directly. Instead, they should extend DynamicConstantDesc (as EnumDesc and VarHandleDesc do.)

Nominal descriptors should be compared using the Object#equals(Object) method. There is no guarantee that any particular entity will always be represented by the same descriptor instance.

Since
12
Java Virtual Machine Specification
4.4 The Constant Pool
See Also
Constable, ConstantDescs

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

the resolved constant value
resolveConstantDesc
(MethodHandles.Lookup
The MethodHandles.Lookup to provide name resolution and access control context
lookup
)

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

resolveConstantDescback to summary
public Object resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException

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.

API Note

Some constant descriptors, such as MethodTypeDesc, can represent a value that is not representable by run-time entities. Attempts to resolve these may result in errors.

Parameters
lookup:MethodHandles.Lookup

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

Returns:Object

the resolved constant value

Exceptions
ReflectiveOperationException:
if a class, method, or field could not be reflectively resolved in the course of resolution
LinkageError:
if a linkage error occurs
Java Virtual Machine Specification
5.4.3 Resolution, 5.4.4 Access Control