-
- All Known Subinterfaces:
ClassDesc,DirectMethodHandleDesc,MethodHandleDesc,MethodTypeDesc
public interface ConstantDescA nominal descriptor for a loadable constant value, as defined in JVMS 4.4. Such a descriptor can be resolved viaresolveConstantDesc(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, andDouble) implementConstantDesc, and serve as nominal descriptors for themselves. Native linkable constants (Class,MethodType, andMethodHandle) have counterpart ConstantDesc types:ClassDesc,MethodTypeDesc, andMethodHandleDesc. Other constants are represented by subtypes ofDynamicConstantDesc.APIs that perform generation or parsing of bytecode are encouraged to use ConstantDesc to describe the operand of an
ldcinstruction (including dynamic constants), the static bootstrap arguments of dynamic constants andinvokedynamicinstructions, and other bytecodes or classfile structures that make use of the constant pool.Constants describing various common constants (such as
ClassDescinstances for platform types) can be found inConstantDescs.Implementations of ConstantDesc must be value-based classes.
Non-platform classes should not implement ConstantDesc directly. Instead, they should extend
DynamicConstantDesc(asEnum.EnumDescandVarHandle.VarHandleDescdo.)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.- API Note:
- In the future, if the Java language permits, ConstantDesc
may become a
sealedinterface, which would prohibit subclassing except by explicitly permitted types. Clients can assume that the following set of subtypes is exhaustive:String,Integer,Long,Float,Double,ClassDesc,MethodTypeDesc,MethodHandleDesc, andDynamicConstantDesc; this list may be extended to reflect future changes to the constant pool format as defined in JVMS 4.4. - Since:
- 12
- See Also:
Constable,ConstantDescs- See The Java™ Virtual Machine Specification:
- 4.4 The Constant Pool
-
-
Method Summary
Modifier and Type Method Description ObjectresolveConstantDesc(MethodHandles.Lookup 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
-
resolveConstantDesc
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 theMethodHandles.Lookupparameter. No caching of the resulting value is performed.- Parameters:
lookup- TheMethodHandles.Lookupto provide name resolution and access control context- Returns:
- the resolved constant value
- Throws:
ReflectiveOperationException- if a class, method, or field could not be reflectively resolved in the course of resolutionLinkageError- if a linkage error occurs- See The Java™ Virtual Machine Specification:
- 5.4.3 Resolution, 5.4.4 Access Control
-
-