public interface Constable
ConstantDesc
. Some constable types have a native representation in the constant pool: String
, Integer
, Long
, Float
, Double
, Class
, MethodType
, and MethodHandle
. The types String
, Integer
, Long
, Float
, and Double
serve as their own nominal descriptors; Class
, MethodType
, and MethodHandle
have corresponding nominal descriptors ClassDesc
, MethodTypeDesc
, and MethodHandleDesc
.
Other reference types can be constable if their instances can describe themselves in nominal form as a ConstantDesc
. Examples in the Java SE Platform API are types that support Java language features such as Enum
, and runtime support classes such as VarHandle
. These are typically described with a DynamicConstantDesc
, which describes dynamically generated constants (JVMS 4.4.10).
The nominal form of an instance of a constable type is obtained via describeConstable()
. A Constable need not be able to (or may choose not to) describe all its instances in the form of a ConstantDesc
; this method returns an Optional
that can be empty to indicate that a nominal descriptor could not be created for an instance. (For example, MethodHandle
will produce nominal descriptors for direct method handles, but not necessarily those produced by method handle combinators.)
CONSTANT_Dynamic_info
and CONSTANT_InvokeDynamic_info
StructuresModifier and Type | Method | Description |
---|---|---|
Optional |
describeConstable() |
Optional<? extends ConstantDesc> describeConstable()
© 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/Constable.html