ClassDesc
, DirectMethodHandleDesc
, MethodHandleDesc
, MethodTypeDesc
public sealed interface ConstantDesc permits ClassDesc, MethodHandleDesc, MethodTypeDesc, Double, DynamicConstantDesc<T>, Float, Integer, Long, String
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 Enum.EnumDesc
and VarHandle.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.
Modifier and Type | Method | Description |
---|---|---|
Object |
resolveConstantDesc |
Object resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException
MethodHandles.Lookup
parameter. No caching of the resulting value is performed.lookup
- The MethodHandles.Lookup
to provide name resolution and access control contextReflectiveOperationException
- if a class, method, or field could not be reflectively resolved in the course of resolutionLinkageError
- if a linkage error occurs
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/constant/ConstantDesc.html