Class Constant


  • public final class Constant
    extends java.lang.Object
    A Constant is used to represent an item in the constant pool of a class.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte CLASS
      Constant tag for class types.
      static byte DOUBLE
      Constant tag for double constants.
      static byte FIELD_REF
      Constant tag for field references.
      static byte FLOAT
      Constant tag for float constants.
      static byte INTEGER
      Constant tag for int, short, byte, char, and boolean constants.
      static byte INTERFACE_METHOD_REF
      Constant tag for method references.
      static byte LONG
      Constant tag for long constants.
      static byte METHOD_REF
      Constant tag for method references.
      static byte NAME_AND_TYPE
      Constant tag for holding the name and type of a field or method.
      static byte STRING
      Constant tag for java.lang.String constants.
      static byte UTF8
      Constant tag for holding the a UTF8 format string.
    • Constructor Summary

      Constructors 
      Constructor Description
      Constant​(int tag, java.lang.Object value)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object other)
      Check if an object is equal to this constant.
      int hashCode()
      Hash the constant.
      int tag()
      Get the tag of the constant.
      java.lang.String toString()
      Convert the constant to a string.
      java.lang.Object value()
      Get the value of the constant.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • CLASS

        public static final byte CLASS
        Constant tag for class types. This is used to reference other classes, such as the superclass, and is used by the checkcast and instanceof instructions. The Fieldref, Methodref and InterfaceMethodref constant types refer to this constant type.
        See Also:
        Constant Field Values
      • FIELD_REF

        public static final byte FIELD_REF
        Constant tag for field references. This is used to reference a field in (possibly) another class. The getfield, putfield, getstatic, and putstatic instructions use this constant type.
        See Also:
        Constant Field Values
      • METHOD_REF

        public static final byte METHOD_REF
        Constant tag for method references. This is used to reference a method in (possibly) another class. The invokevirtual, invokespecial, and invokestatic instructions use this constant type.
        See Also:
        Constant Field Values
      • STRING

        public static final byte STRING
        Constant tag for java.lang.String constants. The actual string value is stored indirectly in a Utf8 constant.
        See Also:
        Constant Field Values
      • INTEGER

        public static final byte INTEGER
        Constant tag for int, short, byte, char, and boolean constants.
        See Also:
        Constant Field Values
      • FLOAT

        public static final byte FLOAT
        Constant tag for float constants.
        See Also:
        Constant Field Values
      • DOUBLE

        public static final byte DOUBLE
        Constant tag for double constants.
        See Also:
        Constant Field Values
      • INTERFACE_METHOD_REF

        public static final byte INTERFACE_METHOD_REF
        Constant tag for method references. This is used to reference a method in an interface. The invokeinterface instruction uses this constant type.
        See Also:
        Constant Field Values
      • NAME_AND_TYPE

        public static final byte NAME_AND_TYPE
        Constant tag for holding the name and type of a field or method. The Fieldref, Methodref and InterfaceMethodref constant types refer to this constant type.
        See Also:
        Constant Field Values
      • UTF8

        public static final byte UTF8
        Constant tag for holding the a UTF8 format string. The string is used to hold the name and type descriptor for NameandType constants, the class name for Class constants, the string value for String constants.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Constant

        public Constant​(int tag,
                        java.lang.Object value)
        Parameters:
        tag - The constant's tag.
        value - The constant's value.
    • Method Detail

      • tag

        public final int tag()
        Get the tag of the constant.
        Returns:
        The tag.
      • value

        public final java.lang.Object value()
        Get the value of the constant.
        Returns:
        The value.
      • hashCode

        public int hashCode()
        Hash the constant.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The hash code.
      • equals

        public boolean equals​(java.lang.Object other)
        Check if an object is equal to this constant.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        other - The object to compare against.
        Returns:
        true if equal, false if not.
      • toString

        public java.lang.String toString()
        Convert the constant to a string.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of the constant.