ConstantPool, Iterable<PoolEntry>public sealed interface ConstantPoolBuilder extends ConstantPool
class file. Provides read and write access to the constant pool that is being built. Writing is append-only (the index of new entries monotonically increase) and idempotent (entry-bearing methods will return an existing entry if there is a suitable one). For class file building, an overload of ClassFile::build takes a ConstantPoolBuilder. For class file transformations via ClassFile::transformClass, the ClassFile.ConstantPoolSharingOption controls how the constant pool builder of the resulting class is created.
class file building and constant pool building, some constant pool entries supplied may be alien to this constant pool builder of the active class file builder. For example, classEntry(Utf8Entry) may be called with an alien UTF8 entry. Alien entries will be converted to a pool entry in this constant pool builder, reusing equivalent entries or adding new entries if there is none. As a result, all pool entries returned by entry-bearing methods in this constant pool builder belong to this constant pool. Some ClassFileBuilder methods may have their outputs adjusted if they receive pool entries alien to their constant pools. For example, if an ldc_w instruction with an alien entry is written to a CodeBuilder, the CodeBuilder may emit a functionally equivalent ldc instruction instead, if the converted entry can be encoded in such an instruction.
To avoid the conversion of alien constant pool entries, such as for the accuracy of the generated class file, users can always supply constant pool entries obtained by calling the constant pool builder entry-bearing methods of the constant pools associated with the
ClassFileBuilder. Otherwise, the conversions have no impact on the behaviors of the generated class files.
| Modifier and Type | Method | Description |
|---|---|---|
BootstrapMethodEntry |
bsmEntry |
Returns a BootstrapMethodEntry referring to a MethodHandleEntry and a list of LoadableConstantEntry. |
default BootstrapMethodEntry |
bsmEntry |
Returns a BootstrapMethodEntry describing the provided bootstrap method and arguments. |
boolean |
canWriteDirect |
Returns true if the index of any entry in the given constant pool refers to the same entry in this builder. |
ClassEntry |
classEntry |
Returns a ClassEntry referring to the provided Utf8Entry. |
default ClassEntry |
classEntry |
Returns a ClassEntry describing the same reference type as the provided ClassDesc. |
ConstantDynamicEntry |
constantDynamicEntry |
|
default ConstantDynamicEntry |
constantDynamicEntry |
Returns a ConstantDynamicEntry describing the dynamic constant as the provided DynamicConstantDesc. |
default ConstantValueEntry |
constantValueEntry |
|
DoubleEntry |
doubleEntry |
Returns a DoubleEntry describing the provided value. |
FieldRefEntry |
fieldRefEntry |
|
default FieldRefEntry |
fieldRefEntry |
Returns a FieldRefEntry describing a field of a class. |
FloatEntry |
floatEntry |
Returns a FloatEntry describing the provided value. |
IntegerEntry |
intEntry |
Returns an IntegerEntry describing the provided value. |
InterfaceMethodRefEntry |
interfaceMethodRefEntry |
|
default InterfaceMethodRefEntry |
interfaceMethodRefEntry |
Returns an InterfaceMethodRefEntry describing a method of an interface. |
InvokeDynamicEntry |
invokeDynamicEntry |
|
default InvokeDynamicEntry |
invokeDynamicEntry |
Returns an InvokeDynamicEntry describing the same dynamic call site as the provided DynamicCallSiteDesc. |
default LoadableConstantEntry |
loadableConstantEntry |
Returns a LoadableConstantEntry describing the provided constant value. |
LongEntry |
longEntry |
Returns a LongEntry describing the provided value. |
MethodHandleEntry |
methodHandleEntry |
Returns a MethodHandleEntry encoding a reference kind and referring to a MemberRefEntry. |
default MethodHandleEntry |
methodHandleEntry |
Returns a MethodHandleEntry describing the same method handle as the given DirectMethodHandleDesc. |
MethodRefEntry |
methodRefEntry |
|
default MethodRefEntry |
methodRefEntry |
Returns a MethodRefEntry describing a method of a class. |
MethodTypeEntry |
methodTypeEntry |
Returns a MethodTypeEntry referring to a Utf8Entry. |
MethodTypeEntry |
methodTypeEntry |
Returns a MethodTypeEntry describing the same method type as the provided MethodTypeDesc. |
ModuleEntry |
moduleEntry |
Returns a ModuleEntry referring to the provided Utf8Entry. |
default ModuleEntry |
moduleEntry |
Returns a ModuleEntry describing the same module as the provided ModuleDesc. |
NameAndTypeEntry |
nameAndTypeEntry |
Returns a NameAndTypeEntry referring to the provided name and type Utf8Entry. |
default NameAndTypeEntry |
nameAndTypeEntry |
Returns a NameAndTypeEntry describing the provided unqualified name and field descriptor. |
default NameAndTypeEntry |
nameAndTypeEntry |
Returns a NameAndTypeEntry describing the provided name and method descriptor. |
static ConstantPoolBuilder |
of() |
Returns a new constant pool builder. |
static ConstantPoolBuilder |
of |
Returns a new constant pool builder. |
PackageEntry |
packageEntry |
Returns a PackageEntry referring to the provided Utf8Entry. |
default PackageEntry |
packageEntry |
Returns a PackageEntry describing the same package as the provided PackageDesc. |
StringEntry |
stringEntry |
Returns a StringEntry referring to a Utf8Entry. |
default StringEntry |
stringEntry |
Returns a StringEntry describing the provided value. |
default Utf8Entry |
utf8Entry |
|
default Utf8Entry |
utf8Entry |
|
Utf8Entry |
utf8Entry |
bootstrapMethodCount, bootstrapMethodEntry, entryByIndex, entryByIndex, iterator, size
forEach, spliterator
static ConstantPoolBuilder of(ClassModel classModel)
size() of the source pool.classModel - the class to copy fromstatic ConstantPoolBuilder of()
1.boolean canWriteDirect(ConstantPool constantPool)
true if the index of any entry in the given constant pool refers to the same entry in this builder. This may be because they are the same builder, or because this builder was pre-populated from the given constant pool. If the constant pool of an entry is not directly writable to this pool, it is alien to this pool, and a ClassFileBuilder associated with this constant pool will convert that alien constant pool entry.
constantPool - the given constant pooltrue if the index of any entry in the given constant pool refers to the same entry in this builderdefault Utf8Entry utf8Entry(ClassDesc desc)
Utf8Entry is usually not referable by a ClassEntry, which uses internal form of binary names.desc - the symbolic descriptor for the classUtf8Entry describing the field descriptor string of the provided ClassDesc
default Utf8Entry utf8Entry(MethodTypeDesc desc)
desc - the symbolic descriptor for the method typeUtf8Entry describing the method descriptor string of the provided MethodTypeDesc
ClassEntry classEntry(Utf8Entry ne)
ClassEntry referring to the provided Utf8Entry. The Utf8Entry describes the internal form of the binary name of a class or interface or the field descriptor string of an array type.ne - the Utf8Entry
ClassEntry referring to the provided Utf8Entry
default ClassEntry classEntry(ClassDesc classDesc)
ClassEntry describing the same reference type as the provided ClassDesc.classDesc - the symbolic descriptor for the reference typeClassEntry describing the same reference type as the provided ClassDesc
IllegalArgumentException - if classDesc represents a primitive typePackageEntry packageEntry(Utf8Entry nameEntry)
PackageEntry referring to the provided Utf8Entry. The Utf8Entry describes the internal form of the name of a package.nameEntry - the Utf8Entry
PackageEntry referring to the provided Utf8Entry
default PackageEntry packageEntry(PackageDesc packageDesc)
PackageEntry describing the same package as the provided PackageDesc.packageDesc - the symbolic descriptor for the packagePackageEntry describing the same package as the provided PackageDesc
ModuleEntry moduleEntry(Utf8Entry moduleName)
moduleName - the constant pool entry describing the module nameModuleEntry referring to the provided Utf8Entry
default ModuleEntry moduleEntry(ModuleDesc moduleDesc)
ModuleEntry describing the same module as the provided ModuleDesc.moduleDesc - the symbolic descriptor for the moduleModuleEntry describing the same module as the provided ModuleDesc
NameAndTypeEntry nameAndTypeEntry(Utf8Entry nameEntry, Utf8Entry typeEntry)
NameAndTypeEntry referring to the provided name and type Utf8Entry. The name Utf8Entry describes an unqualified name or the special name "<init>", and the type Utf8Entry describes a field or method descriptor string.nameEntry - the name Utf8Entry
typeEntry - the type Utf8Entry
NameAndTypeEntry referring to the provided name and type Utf8Entry
default NameAndTypeEntry nameAndTypeEntry(String name, ClassDesc type)
NameAndTypeEntry describing the provided unqualified name and field descriptor.name - the unqualified nametype - the field descriptorNameAndTypeEntry describing the provided unqualified name and field descriptordefault NameAndTypeEntry nameAndTypeEntry(String name, MethodTypeDesc type)
NameAndTypeEntry describing the provided name and method descriptor. The name can be an unqualified name or the special name "<init>".name - the unqualified name, or "<init>"
type - the method descriptorNameAndTypeEntry describing the provided name and method descriptorFieldRefEntry fieldRefEntry(ClassEntry owner, NameAndTypeEntry nameAndType)
FieldRefEntry referring to a ClassEntry and a NameAndTypeEntry. The ClassEntry describes a class or interface that has this field as a member, and the
NameAndTypeEntry describes the unqualified name and the field descriptor for this field.owner - the ClassEntry
nameAndType - the NameAndTypeEntry
FieldRefEntry referring to a ClassEntry and a NameAndTypeEntry
default FieldRefEntry fieldRefEntry(ClassDesc owner, String name, ClassDesc type)
FieldRefEntry describing a field of a class.owner - the class or interface the field is a member ofname - the unqualified name of the fieldtype - the field descriptorFieldRefEntry describing a field of a classIllegalArgumentException - if owner represents a primitive typeMethodRefEntry methodRefEntry(ClassEntry owner, NameAndTypeEntry nameAndType)
MethodRefEntry referring to a ClassEntry and a NameAndTypeEntry. The ClassEntry describes a class that has this method as a member, and the NameAndTypeEntry describes the unqualified name or the special name "<init>" and the method descriptor for this method.owner - the ClassEntry
nameAndType - the NameAndTypeEntry
MethodRefEntry referring to a ClassEntry and a NameAndTypeEntry
default MethodRefEntry methodRefEntry(ClassDesc owner, String name, MethodTypeDesc type)
MethodRefEntry describing a method of a class.owner - the class the method is a member ofname - the unqualified name, or special name "<init>", of the methodtype - the method descriptorMethodRefEntry describing a method of a classIllegalArgumentException - if owner represents a primitive typeInterfaceMethodRefEntry interfaceMethodRefEntry(ClassEntry owner, NameAndTypeEntry nameAndType)
InterfaceMethodRefEntry referring to a ClassEntry and a NameAndTypeEntry. The ClassEntry describes an interface that has this method as a member, and the
NameAndTypeEntry describes the unqualified name and the method descriptor for this method.owner - the ClassEntry
nameAndType - the NameAndTypeEntry
InterfaceMethodRefEntry referring to a ClassEntry and a NameAndTypeEntry
default InterfaceMethodRefEntry interfaceMethodRefEntry(ClassDesc owner, String name, MethodTypeDesc type)
InterfaceMethodRefEntry describing a method of an interface.owner - the interface the method is a member ofname - the unqualified name of the methodtype - the method descriptorInterfaceMethodRefEntry describing a method of an interfaceIllegalArgumentException - if owner represents a primitive typeMethodTypeEntry methodTypeEntry(MethodTypeDesc descriptor)
MethodTypeEntry describing the same method type as the provided MethodTypeDesc.descriptor - the symbolic descriptor of the method typeMethodTypeEntry describing the same method type as the provided MethodTypeDesc
MethodTypeEntry methodTypeEntry(Utf8Entry descriptor)
MethodTypeEntry referring to a Utf8Entry. The Utf8Entry represents a method descriptor string.descriptor - the Utf8Entry
MethodTypeEntry referring to a Utf8Entry
default MethodHandleEntry methodHandleEntry(DirectMethodHandleDesc descriptor)
MethodHandleEntry describing the same method handle as the given DirectMethodHandleDesc.descriptor - the symbolic descriptor of the method handleMethodHandleEntry describing the same method handle as the given DirectMethodHandleDesc
MethodHandleEntry methodHandleEntry(int refKind, MemberRefEntry reference)
MethodHandleEntry encoding a reference kind and referring to a MemberRefEntry. The reference kind must be in [1, 9], and the MemberRefEntry is subject to various restrictions based on the reference kind (JVMS 4.4.8).refKind - the reference kind of the method handlereference - the MemberRefEntry
MethodHandleEntry encoding a reference kind and referring to a MemberRefEntry
default InvokeDynamicEntry invokeDynamicEntry(DynamicCallSiteDesc dcsd)
InvokeDynamicEntry describing the same dynamic call site as the provided DynamicCallSiteDesc.dcsd - the symbolic descriptor of the dynamic call siteInvokeDynamicEntry describing the same dynamic call site as the provided DynamicCallSiteDesc
InvokeDynamicEntry invokeDynamicEntry(BootstrapMethodEntry bootstrapMethodEntry, NameAndTypeEntry nameAndType)
InvokeDynamicEntry referring to a BootstrapMethodEntry and a NameAndTypeEntry. The BootstrapMethodEntry describes the bootstrap method and its invocation arguments in addition to the name and type, and the NameAndTypeEntry a name and a method descriptor.bootstrapMethodEntry - the BootstrapMethodEntry
nameAndType - the NameAndTypeEntry
InvokeDynamicEntry referring to a BootstrapMethodEntry and a NameAndTypeEntry
default ConstantDynamicEntry constantDynamicEntry(DynamicConstantDesc<?> dcd)
ConstantDynamicEntry describing the dynamic constant as the provided DynamicConstantDesc.dcd - the symbolic descriptor of the constantConstantDynamicEntry describing the dynamic constant as the provided DynamicConstantDesc
ConstantDynamicEntry constantDynamicEntry(BootstrapMethodEntry bootstrapMethodEntry, NameAndTypeEntry nameAndType)
ConstantDynamicEntry referring to a BootstrapMethodEntry and a NameAndTypeEntry. The BootstrapMethodEntry describes the bootstrap method and its invocation arguments in addition to the name and type, and the NameAndTypeEntry a name and a field descriptor.bootstrapMethodEntry - the BootstrapMethodEntry
nameAndType - the NameAndTypeEntry
ConstantDynamicEntry referring to a BootstrapMethodEntry and a NameAndTypeEntry
IntegerEntry intEntry(int value)
IntegerEntry describing the provided value.value - the valueIntegerEntry describing the provided valueFloatEntry floatEntry(float value)
FloatEntry describing the provided value. All NaN values of the float may or may not be collapsed into a single "canonical" NaN value.
value - the valueFloatEntry describing the provided valueDoubleEntry doubleEntry(double value)
DoubleEntry describing the provided value. All NaN values of the double may or may not be collapsed into a single "canonical" NaN value.
value - the valueDoubleEntry describing the provided valueStringEntry stringEntry(Utf8Entry utf8)
utf8 - the Utf8Entry
StringEntry referring to a Utf8Entry
default StringEntry stringEntry(String value)
StringEntry describing the provided value.value - the valueStringEntry describing the provided valuedefault ConstantValueEntry constantValueEntry(ConstantDesc c)
ConstantValueEntry describing the provided constant Integer, Long, Float, Double, or String value.c - the provided constant valueConstantValueEntry describing the provided constant Integer, Long, Float, Double, or String valueIllegalArgumentException - if the value is not one of
Integer, Long, Float, Double, or
String
default LoadableConstantEntry loadableConstantEntry(ConstantDesc c)
LoadableConstantEntry describing the provided constant value.c - the nominal descriptor for the constantLoadableConstantEntry describing the provided constant valuedefault BootstrapMethodEntry bsmEntry(DirectMethodHandleDesc methodReference, List<ConstantDesc> arguments)
BootstrapMethodEntry describing the provided bootstrap method and arguments.methodReference - the bootstrap methodarguments - the argumentsBootstrapMethodEntry describing the provided bootstrap method and argumentsBootstrapMethodEntry bsmEntry(MethodHandleEntry methodReference, List<LoadableConstantEntry> arguments)
BootstrapMethodEntry referring to a MethodHandleEntry and a list of LoadableConstantEntry. The MethodHandleEntry is the bootstrap method, and the list of LoadableConstantEntry is the arguments.methodReference - the MethodHandleEntry
arguments - the list of LoadableConstantEntry
BootstrapMethodEntry referring to a MethodHandleEntry and a list of LoadableConstantEntry
© 1993, 2025, 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/25/docs/api/java.base/java/lang/classfile/constantpool/ConstantPoolBuilder.html