APIdia Launch Partner
Top Description Methods
java.lang.classfile.constantpool

public sealed Interface ConstantPool

extends Iterable<PoolEntry>
permits ClassReader, ConstantPoolBuilder
Known Direct Subinterfaces
java.lang.classfile.constantpool.ConstantPoolBuilder, java.lang.classfile.ClassReader
Imports
java.lang.classfile.BootstrapMethodEntry, .ClassReader, java.lang.classfile.attribute.BootstrapMethodsAttribute, java.util.Iterator, .NoSuchElementException

Provides read access to the constant pool and the bootstrap method table of a class file.

Index in the Constant Pool

The constant pool entries are accessed by index. A valid index is in the range of [1, size()). It is unusable if a LongEntry or DoubleEntry is at its previous index.
Since
24
Java Virtual Machine Specification
4.4 The Constant Pool
See Also
BootstrapMethodsAttribute

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the number of entries in the bootstrap method table
bootstrapMethodCount
()

Returns the number of entries in the bootstrap method table.

public BootstrapMethodEntry

Returns:

the BootstrapMethodEntry at the specified index within the bootstrap method table
bootstrapMethodEntry
(int
the index within the bootstrap method table of the desired entry
index
)

Returns the BootstrapMethodEntry at the specified index within the bootstrap method table.

public PoolEntry

Returns:

the entry at the specified index
entryByIndex
(int
the index within the pool of the desired entry
index
)

Returns the entry at the specified index.

public <
the entry type
T extends PoolEntry
>
T

Returns:

the entry of a given type at the specified index
entryByIndex
(int
the index within the pool of the desired entry
index
,
Class<T>
the entry type
cls
)

Returns the entry of a given type at the specified index.

public default Iterator<PoolEntry>

Returns:

an iterator over pool entries
iterator
()

Implements java.lang.Iterable.iterator.

Returns an iterator over pool entries.

public int

Returns:

the exclusive upper bound of the valid indices of this constant pool
size
()

Returns the exclusive upper bound of the valid indices of this constant pool.

Inherited from java.lang.Iterable:
forEachspliterator

Method Detail

bootstrapMethodCountback to summary
public int bootstrapMethodCount()

Returns the number of entries in the bootstrap method table.

Returns:int

the number of entries in the bootstrap method table

bootstrapMethodEntryback to summary
public BootstrapMethodEntry bootstrapMethodEntry(int index)

Returns the BootstrapMethodEntry at the specified index within the bootstrap method table.

Parameters
index:int

the index within the bootstrap method table of the desired entry

Returns:BootstrapMethodEntry

the BootstrapMethodEntry at the specified index within the bootstrap method table

Exceptions
ConstantPoolException:
if the index is out of range of the bootstrap methods
entryByIndexback to summary
public PoolEntry entryByIndex(int index)

Returns the entry at the specified index.

API Note

If only a particular type of entry is expected, use entryByIndex( int, Class).

Parameters
index:int

the index within the pool of the desired entry

Returns:PoolEntry

the entry at the specified index

Exceptions
ConstantPoolException:
if the index is out of range of the constant pool, or is considered unusable
entryByIndexback to summary
public <T extends PoolEntry> T entryByIndex(int index, Class<T> cls)

Returns the entry of a given type at the specified index.

Parameters
<T>
the entry type
index:int

the index within the pool of the desired entry

cls:Class<T>

the entry type

Returns:T

the entry of a given type at the specified index

Exceptions
ConstantPoolException:
if the index is out of range of the constant pool or considered unusable, or the entry is not of the given type
iteratorback to summary
public default Iterator<PoolEntry> iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over pool entries.

API Note

This skips any unusable index and is less error-prone than iterating by raw index. See Index in the Constant Pool.

Returns:Iterator<PoolEntry>

an iterator over pool entries

Annotations
@Override
sizeback to summary
public int size()

Returns the exclusive upper bound of the valid indices of this constant pool. The actual number of entries is lower because 0, size() are not valid, and a valid index may be unusable.

Returns:int

the exclusive upper bound of the valid indices of this constant pool

See Also
Index in the Constant Pool