org.apache.bcel.classfile

## Class ConstantCP

- java.lang.Object
- - org.apache.bcel.classfile.Constant
  - - org.apache.bcel.classfile.ConstantCP

- All Implemented Interfaces:
    Cloneable, Node
  Direct Known Subclasses:
    ConstantDynamic, ConstantFieldref, ConstantInterfaceMethodref, ConstantInvokeDynamic, ConstantMethodref

      public abstract class ConstantCP
      extends Constant

  Abstract super class for Fieldref, Methodref, InterfaceMethodref and InvokeDynamic constants.
  See Also:
    `ConstantFieldref`, `ConstantMethodref`, `ConstantInterfaceMethodref`, `ConstantInvokeDynamic`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `class_index` Deprecated. (since 6.0) will be made private; do not access directly, use getter/setter
    `protected int` | `name_and_type_index` Deprecated. (since 6.0) will be made private; do not access directly, use getter/setter

    - ### Fields inherited from class org.apache.bcel.classfile.Constant

      `tag`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ConstantCP(byte tag, int classIndex, int nameAndTypeIndex)`
    `` | `ConstantCP(ConstantCP c)` Initialize from another object.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `dump(DataOutputStream file)` Dump constant field reference to file stream in binary format.
    `String` | `getClass(ConstantPool cp)`
    `int` | `getClassIndex()`
    `int` | `getNameAndTypeIndex()`
    `void` | `setClassIndex(int classIndex)`
    `void` | `setNameAndTypeIndex(int nameAndTypeIndex)`
    `String` | `toString()`

    - ### Methods inherited from class org.apache.bcel.classfile.Constant

      `accept, clone, copy, equals, getComparator, getTag, hashCode, readConstant, setComparator`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### class_index

          @Deprecated
          protected int class_index

      Deprecated. (since 6.0) will be made private; do not access directly, use getter/setter

    - #### name_and_type_index

          @Deprecated
          protected int name_and_type_index

      Deprecated. (since 6.0) will be made private; do not access directly, use getter/setter

  - ### Constructor Detail

    - #### ConstantCP

          protected ConstantCP(byte tag,
                               int classIndex,
                               int nameAndTypeIndex)

      Parameters:
        `classIndex` - Reference to the class containing the field
        `nameAndTypeIndex` - and the field signature

    - #### ConstantCP

          public ConstantCP(ConstantCP c)

      Initialize from another object.
      Parameters:
        `c` - Source to copy.

  - ### Method Detail

    - #### dump

          public final void dump(DataOutputStream file)
                          throws IOException

      Dump constant field reference to file stream in binary format.
      Specified by:
        `dump` in class `Constant`
      Parameters:
        `file` - Output file stream
      Throws:
        `IOException` - if an I/O error occurs.

    - #### getClass

          public String getClass(ConstantPool cp)

      Returns:
        Class this field belongs to.

    - #### getClassIndex

          public final int getClassIndex()

      Returns:
        Reference (index) to class this constant refers to.

    - #### getNameAndTypeIndex

          public final int getNameAndTypeIndex()

      Returns:
        Reference (index) to signature of the field.

    - #### setClassIndex

          public final void setClassIndex(int classIndex)

      Parameters:
        `classIndex` - points to Constant_class

    - #### setNameAndTypeIndex

          public final void setNameAndTypeIndex(int nameAndTypeIndex)

      Parameters:
        `nameAndTypeIndex` - points to Constant_NameAndType

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Constant`
      Returns:
        String representation. not final as ConstantInvokeDynamic needs to modify

Copyright © 2004–2022 The Apache Software Foundation. All rights reserved.