InvokeInstruction (Java SE 26 & JDK 26)
Description: declaration: module: java.base, package: java.lang.classfile.instruction, interface: InvokeInstruction
Keywords: java.lang.classfile.instruction.InvokeInstruction interface

# Interface InvokeInstruction

All Superinterfaces:
  `ClassFileElement, CodeElement, Instruction`

public sealed interface InvokeInstruction extends Instruction
Models a method invocation instruction in the `code` array of a `Code` attribute, other than `invokedynamic`. Corresponding opcodes have a kind of `Opcode.Kind.INVOKE`. Delivered as a `CodeElement` when traversing the elements of a `CodeModel`.

A method invocation instruction is composite:

    InvokeInstruction(
        Opcode opcode,
        MethodRefEntry | InterfaceMethodRefEntry method)
    )

where `method` must be an `InterfaceMethodRefEntry` for `invokeinterface` opcode, and must be a `MethodRefEntry` for `invokevirtual` opcode. `invokestatic` and `invokespecial` can have either type of entry for `method`.

Since:
  24
See Also:
  - `Opcode.Kind.INVOKE`
  - `CodeBuilder::invoke`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `count()`
  Returns the `count` value of an `invokeinterface` instruction, or `0` for other instructions.
  `boolean`
  `isInterface()`
  Returns whether the class or interface holding the method is an interface.
  `MemberRefEntry`
  `method()`
  Returns the `MethodRefEntry` or `InterfaceMethodRefEntry` constant described by this instruction.
  `default Utf8Entry`
  `name()`
  Returns the name of the method.
  `static InvokeInstruction`
  `of(Opcode op, ClassEntry owner, NameAndTypeEntry nameAndType, boolean isInterface)`
  Returns an invocation instruction.
  `static InvokeInstruction`
  `of(Opcode op, ClassEntry owner, Utf8Entry name, Utf8Entry type, boolean isInterface)`
  Returns an invocation instruction.
  `static InvokeInstruction`
  `of(Opcode op, MemberRefEntry method)`
  Returns an invocation instruction.
  `default ClassEntry`
  `owner()`
  Returns the class or interface holding the method.
  `default Utf8Entry`
  `type()`
  Returns the method descriptor string of the method.
  `default MethodTypeDesc`
  `typeSymbol()`
  Returns a symbolic descriptor for the method type.

  ### Methods declared in interface Instruction

  `opcode, sizeInBytes`
  Modifier and Type
  Method
  Description
  `Opcode`
  `opcode()`
  Returns the operation of this instruction.
  `int`
  `sizeInBytes()`
  Returns the size in bytes of this instruction.

- ## Method Details

  - ### method

    MemberRefEntry method()
    Returns the `MethodRefEntry` or `InterfaceMethodRefEntry` constant described by this instruction.
    Returns:
      the `MethodRefEntry` or `InterfaceMethodRefEntry` constant described by this instruction

  - ### isInterface

    boolean isInterface()
    Returns whether the class or interface holding the method is an interface.
    Returns:
      whether the class or interface holding the method is an interface

  - ### count

    int count()
    Returns the `count` value of an `invokeinterface` instruction, or `0` for other instructions.

    For an `invokeinterface` instruction, this value must be equivalent to the sum of slot sizes of all arguments plus one, which is equal to the number of operand stack depth consumed by this interface method invocation instruction.

    Returns:
      the `count` value of an `invokeinterface` instruction, or `0` for other instructions
    See Java Virtual Machine Specification:
      6.5.invokeinterface invokeinterface

  - ### owner

    default ClassEntry owner()
    Returns the class or interface holding the method.
    Returns:
      the class or interface holding the method

  - ### name

    default Utf8Entry name()
    Returns the name of the method.
    Returns:
      the name of the method

  - ### type

    default Utf8Entry type()
    Returns the method descriptor string of the method.
    API Note:
      A symbolic descriptor for the type of the method is available through `typeSymbol()`.
    Returns:
      the method descriptor string of the method

  - ### typeSymbol

    default MethodTypeDesc typeSymbol()
    Returns a symbolic descriptor for the method type.
    Returns:
      a symbolic descriptor for the method type

  - ### of

    static InvokeInstruction of(Opcode op, MemberRefEntry method)
    Returns an invocation instruction.
    Parameters:
      `op` - the opcode for the specific type of invocation instruction, which must be of kind `Opcode.Kind.INVOKE`
      `method` - a constant pool entry describing the method
    Returns:
      an invocation instruction
    Throws:
      `IllegalArgumentException` - if the opcode kind is not `Opcode.Kind.INVOKE`

  - ### of

    static InvokeInstruction of(Opcode op, ClassEntry owner, Utf8Entry name, Utf8Entry type, boolean isInterface)
    Returns an invocation instruction.
    Parameters:
      `op` - the opcode for the specific type of invocation instruction, which must be of kind `Opcode.Kind.INVOKE`
      `owner` - the class holding the method
      `name` - the name of the method
      `type` - the method descriptor
      `isInterface` - whether the class holding the method is an interface
    Returns:
      an invocation instruction
    Throws:
      `IllegalArgumentException` - if the opcode kind is not `Opcode.Kind.INVOKE`

  - ### of

    static InvokeInstruction of(Opcode op, ClassEntry owner, NameAndTypeEntry nameAndType, boolean isInterface)
    Returns an invocation instruction.
    Parameters:
      `op` - the opcode for the specific type of invocation instruction, which must be of kind `Opcode.Kind.INVOKE`
      `owner` - the class holding the method
      `nameAndType` - the name and type of the method
      `isInterface` - whether the class holding the method is an interface
    Returns:
      an invocation instruction
    Throws:
      `IllegalArgumentException` - if the opcode kind is not `Opcode.Kind.INVOKE`