# Class Field

java.lang.Object
org.apache.bcel.classfile.AccessFlags
org.apache.bcel.classfile.FieldOrMethod
org.apache.bcel.classfile.Field

All Implemented Interfaces:
  `Cloneable, Node`

public final class Field extends FieldOrMethod
This class represents the field info structure, that is, the representation for a variable in the class. See JVM specification for details.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final Field[]`
  `EMPTY_ARRAY`
  Empty array constant.

  ### Fields inherited from class FieldOrMethod

  `attributes, attributes_count, constant_pool, name_index, signature_index`

  ### Fields inherited from class AccessFlags

  `access_flags`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Field(int accessFlags, int nameIndex, int signatureIndex, Attribute[] attributes, ConstantPool constantPool)`
  Constructs a Field.
  `Field(Field c)`
  Initialize from another object.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `accept(Visitor v)`
  Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class.
  `Field`
  `copy(ConstantPool constantPool)`
  Creates a deep copy of this field.
  `boolean`
  `equals(Object obj)`
  Return value as defined by given BCELComparator strategy.
  `static BCELComparator<Field>`
  `getComparator()`
  Gets the comparison strategy object.
  `ConstantValue`
  `getConstantValue()`
  Gets the constant value associated with this field.
  `Type`
  `getType()`
  See https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.2.2
  `int`
  `hashCode()`
  Return value as defined by given BCELComparator strategy.
  `static void`
  `setComparator(BCELComparator<Field> comparator)`
  Sets the comparison strategy object.
  `String`
  `toString()`
  Return string representation close to declaration format, for example: 'public static final short MAX = 100'.

  ### Methods inherited from class FieldOrMethod

  `copy_, dump, getAnnotationEntries, getAttribute, getAttributes, getConstantPool, getGenericSignature, getName, getNameIndex, getSignature, getSignatureIndex, setAttributes, setConstantPool, setNameIndex, setSignatureIndex`

  ### Methods inherited from class AccessFlags

  `getAccessFlags, getModifiers, isAbstract, isAbstract, isAnnotation, isAnnotation, isEnum, isEnum, isFinal, isFinal, isInterface, isInterface, isNative, isNative, isPrivate, isPrivate, isProtected, isProtected, isPublic, isPublic, isStatic, isStatic, isStrictfp, isStrictfp, isSynchronized, isSynchronized, isSynthetic, isSynthetic, isTransient, isTransient, isVarArgs, isVarArgs, isVolatile, isVolatile, setAccessFlags, setModifiers`

  ### Methods inherited from class Object

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

- ## Field Details

  - ### EMPTY_ARRAY

    public static final Field[] EMPTY_ARRAY
    Empty array constant.
    Since:
      6.6.0

- ## Constructor Details

  - ### Field

    public Field(Field c)
    Initialize from another object. Note that both objects use the same references (shallow copy). Use clone() for a physical copy.
    Parameters:
      `c` - Source to copy.

  - ### Field

    public Field(int accessFlags, int nameIndex, int signatureIndex, Attribute[] attributes, ConstantPool constantPool)
    Constructs a Field.
    Parameters:
      `accessFlags` - Access rights of field.
      `nameIndex` - Points to field name in constant pool.
      `signatureIndex` - Points to encoded signature.
      `attributes` - Collection of attributes.
      `constantPool` - Array of constants.

- ## Method Details

  - ### getComparator

    public static BCELComparator<Field> getComparator()
    Gets the comparison strategy object.
    Returns:
      Comparison strategy object.

  - ### setComparator

    public static void setComparator(BCELComparator<Field> comparator)
    Sets the comparison strategy object.
    Parameters:
      `comparator` - Comparison strategy object.

  - ### accept

    public 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.
    Parameters:
      `v` - Visitor object.

  - ### copy

    public Field copy(ConstantPool constantPool)
    Creates a deep copy of this field.
    Parameters:
      `constantPool` - the constant pool.
    Returns:
      deep copy of this field.

  - ### equals

    public boolean equals(Object obj)
    Return value as defined by given BCELComparator strategy. By default two Field objects are said to be equal when their names and signatures are equal.
    Overrides:
      `equals` in class `Object`
    See Also:
      - `Object.equals(Object)`

  - ### getConstantValue

    public ConstantValue getConstantValue()
    Gets the constant value associated with this field.
    Returns:
      constant value associated with this field (may be null).

  - ### getType

    public Type getType()
    See https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.2.2
    Returns:
      type of field.

  - ### hashCode

    public int hashCode()
    Return value as defined by given BCELComparator strategy. By default return the hash code of the field's name XOR signature.
    Overrides:
      `hashCode` in class `Object`
    See Also:
      - `Object.hashCode()`

  - ### toString

    public String toString()
    Return string representation close to declaration format, for example: 'public static final short MAX = 100'.
    Overrides:
      `toString` in class `Object`
    Returns:
      String representation of field, including the signature.