ConstantPool (Apache Tomcat 9.0.111 API Documentation)
Description: declaration: package: org.apache.tomcat.util.bcel.classfile, class: ConstantPool

# Class ConstantPool

java.lang.Object
org.apache.tomcat.util.bcel.classfile.ConstantPool

public class ConstantPool extends Object
This class represents the constant pool, i.e., a table of constants, of a parsed classfile. It may contain null references, due to the JVM specification that skips an entry after an 8-byte constant (double, long) entry. Those interested in generating constant pools programmatically should see ConstantPoolGen.

See Also:
  - `Constant`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `<T extends Constant>
  T`
  `getConstant(int index)`
  Gets constant from constant pool.
  `<T extends Constant>
  T`
  `getConstant(int index, byte tag)`
  Gets constant from constant pool and check whether it has the expected type.
  `<T extends Constant>
  T`
  `getConstant(int index, Class<T> castTo)`
  Gets constant from constant pool.
  `ConstantInteger`
  `getConstantInteger(int index)`
  Gets constant from constant pool and check whether it has the expected type.
  `ConstantUtf8`
  `getConstantUtf8(int index)`
  Gets constant from constant pool and check whether it has the expected type.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### getConstant

    public <T extends Constant> T getConstant(int index) throws ClassFormatException
    Gets constant from constant pool.
    Type Parameters:
      `T` - A `Constant` subclass
    Parameters:
      `index` - Index in constant pool
    Returns:
      Constant value
    Throws:
      `ClassFormatException` - if index is invalid
    See Also:
      - `Constant`

  - ### getConstant

    public <T extends Constant> T getConstant(int index, byte tag) throws ClassFormatException
    Gets constant from constant pool and check whether it has the expected type.
    Type Parameters:
      `T` - A `Constant` subclass
    Parameters:
      `index` - Index in constant pool
      `tag` - Tag of expected constant, i.e., its type
    Returns:
      Constant value
    Throws:
      `ClassFormatException` - if constant type does not match tag
    See Also:
      - `Constant`

  - ### getConstant

    public <T extends Constant> T getConstant(int index, Class<T> castTo) throws ClassFormatException
    Gets constant from constant pool.
    Type Parameters:
      `T` - A `Constant` subclass
    Parameters:
      `index` - Index in constant pool
      `castTo` - The `Constant` subclass to cast to.
    Returns:
      Constant value
    Throws:
      `ClassFormatException` - if index is invalid
    See Also:
      - `Constant`

  - ### getConstantInteger

    public ConstantInteger getConstantInteger(int index)
    Gets constant from constant pool and check whether it has the expected type.
    Parameters:
      `index` - Index in constant pool
    Returns:
      ConstantInteger value
    Throws:
      `ClassFormatException` - if constant type does not match tag
    See Also:
      - `ConstantInteger`

  - ### getConstantUtf8

    public ConstantUtf8 getConstantUtf8(int index) throws ClassFormatException
    Gets constant from constant pool and check whether it has the expected type.
    Parameters:
      `index` - Index in constant pool
    Returns:
      ConstantUtf8 value
    Throws:
      `ClassFormatException` - if constant type does not match tag
    See Also:
      - `ConstantUtf8`