Package org.apache.bcel.classfile

# Class Constant

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

All Implemented Interfaces:
  `Cloneable`, `Node`

Direct Known Subclasses:
  `ConstantClass`, `ConstantCP`, `ConstantDouble`, `ConstantFloat`, `ConstantInteger`, `ConstantLong`, `ConstantMethodHandle`, `ConstantMethodType`, `ConstantModule`, `ConstantNameAndType`, `ConstantPackage`, `ConstantString`, `ConstantUtf8`

public abstract class Constant extends Object implements Cloneable, Node
Abstract superclass for classes to represent the different constant types in the constant pool of a class file. The classes keep closely to the JVM specification.

- ## Field Summary

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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract void`
  `accept(Visitor v)`
  Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class.
  `Object`
  `clone()`
  `Constant`
  `copy()`
  `abstract void`
  `dump(DataOutputStream file)`
  `boolean`
  `equals(Object obj)`
  Returns value as defined by given BCELComparator strategy.
  `static BCELComparator<Constant>`
  `getComparator()`
  `final byte`
  `getTag()`
  `int`
  `hashCode()`
  Returns value as defined by given BCELComparator strategy.
  `static Constant`
  `readConstant(DataInput dataInput)`
  Reads one constant from the given input, the type depends on a tag byte.
  `static void`
  `setComparator(BCELComparator<Constant> comparator)`
  `String`
  `toString()`

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

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

- ## Field Details

  - ### tag

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

- ## Method Details

  - ### getComparator

    public static BCELComparator<Constant> getComparator()
    Returns:
      Comparison strategy object.

  - ### readConstant

    public static Constant readConstant(DataInput dataInput) throws IOException, ClassFormatException
    Reads one constant from the given input, the type depends on a tag byte.
    Parameters:
      `dataInput` - Input stream
    Returns:
      Constant object
    Throws:
      `IOException` - if an I/O error occurs reading from the given `dataInput`.
      `ClassFormatException` - if the next byte is not recognized
    Since:
      6.0 made public

  - ### setComparator

    public static void setComparator(BCELComparator<Constant> comparator)
    Parameters:
      `comparator` - Comparison strategy object

  - ### accept

    public abstract void accept(Visitor v)
    Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class. I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
    Specified by:
      `accept` in interface `Node`
    Parameters:
      `v` - Visitor object

  - ### clone

    public Object clone()
    Overrides:
      `clone` in class `Object`

  - ### copy

    public Constant copy()
    Returns:
      deep copy of this constant

  - ### dump

    public abstract void dump(DataOutputStream file) throws IOException
    Throws:
      `IOException`

  - ### equals

    public boolean equals(Object obj)
    Returns value as defined by given BCELComparator strategy. By default two Constant objects are said to be equal when the result of toString() is equal.
    Overrides:
      `equals` in class `Object`
    See Also:
      - `Object.equals(Object)`

  - ### getTag

    public final byte getTag()
    Returns:
      Tag of constant, i.e., its type. No setTag() method to avoid confusion.

  - ### hashCode

    public int hashCode()
    Returns value as defined by given BCELComparator strategy. By default return the hash code of the result of toString().
    Overrides:
      `hashCode` in class `Object`
    See Also:
      - `Object.hashCode()`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`
    Returns:
      String representation.