# Class FieldOrMethod

java.lang.Object
org.apache.bcel.generic.Instruction
org.apache.bcel.generic.CPInstruction
org.apache.bcel.generic.FieldOrMethod

All Implemented Interfaces:
  `Cloneable, IndexedInstruction, LoadClass, TypedInstruction`

Direct Known Subclasses:
  `FieldInstruction, InvokeInstruction`

public abstract class FieldOrMethod extends CPInstruction implements LoadClass
Super class for InvokeInstruction and FieldInstruction, since they have some methods in common!

- ## Field Summary

  ### Fields inherited from class CPInstruction

  `index`

  ### Fields inherited from class Instruction

  `length, opcode`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `FieldOrMethod(short opcode, int index)`
  Constructs a FieldOrMethod.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getClassName(ConstantPoolGen cpg)`
  Deprecated.
  If the instruction references an array class, this method will return "java.lang.Object".
  `ObjectType`
  `getClassType(ConstantPoolGen cpg)`
  Deprecated.
  If the instruction references an array class, the ObjectType returned will be invalid.
  `ObjectType`
  `getLoadClassType(ConstantPoolGen cpg)`
  Gets the ObjectType of the method return or field.
  `String`
  `getName(ConstantPoolGen cpg)`
  Gets the name of referenced method or field.
  `ReferenceType`
  `getReferenceType(ConstantPoolGen cpg)`
  Gets the reference type representing the class, interface, or array class referenced by the instruction.
  `String`
  `getSignature(ConstantPoolGen cpg)`
  Gets the signature of referenced method or field.

  ### Methods inherited from class CPInstruction

  `dump, getIndex, getType, initFromFile, setIndex, toString, toString`

  ### Methods inherited from class Instruction

  `accept, consumeStack, copy, equals, getComparator, getLength, getName, getOpcode, hashCode, isValidByte, isValidShort, produceStack, readInstruction, setComparator, toString`

  ### Methods inherited from class Object

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

  ### Methods inherited from interface LoadClass

  `getType`

- ## Constructor Details

  - ### FieldOrMethod

    protected FieldOrMethod(short opcode, int index)
    Constructs a FieldOrMethod.
    Parameters:
      `opcode` - the opcode.
      `index` - to constant pool.

- ## Method Details

  - ### getClassName

    @Deprecated public String getClassName(ConstantPoolGen cpg)
    Deprecated.
    If the instruction references an array class, this method will return "java.lang.Object". For code generated by Java 1.5, this answer is sometimes wrong (for example, if the "clone()" method is called on an array). A better idea is to use the `getReferenceType(ConstantPoolGen)` method, which correctly distinguishes between class types and array types.
    Gets the name of the referenced class/interface.
    Parameters:
      `cpg` - the constant pool generator.
    Returns:
      name of the referenced class/interface.

  - ### getClassType

    @Deprecated public ObjectType getClassType(ConstantPoolGen cpg)
    Deprecated.
    If the instruction references an array class, the ObjectType returned will be invalid. Use getReferenceType() instead.
    Gets the type of the referenced class/interface.
    Parameters:
      `cpg` - the constant pool generator.
    Returns:
      type of the referenced class/interface.

  - ### getLoadClassType

    public ObjectType getLoadClassType(ConstantPoolGen cpg)
    Gets the ObjectType of the method return or field.
    Specified by:
      `getLoadClassType` in interface `LoadClass`
    Parameters:
      `cpg` - the constant pool generator.
    Returns:
      type of the referenced class/interface.
    Throws:
      `ClassGenException` - when the field is (or method returns) an array.

  - ### getName

    public String getName(ConstantPoolGen cpg)
    Gets the name of referenced method or field.
    Parameters:
      `cpg` - the constant pool generator.
    Returns:
      name of referenced method/field.

  - ### getReferenceType

    public ReferenceType getReferenceType(ConstantPoolGen cpg)
    Gets the reference type representing the class, interface, or array class referenced by the instruction.
    Parameters:
      `cpg` - the ConstantPoolGen used to create the instruction.
    Returns:
      an ObjectType (if the referenced class type is a class or interface), or an ArrayType (if the referenced class type is an array class)

  - ### getSignature

    public String getSignature(ConstantPoolGen cpg)
    Gets the signature of referenced method or field.
    Parameters:
      `cpg` - the constant pool generator.
    Returns:
      signature of referenced method/field.