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

# Interface ConvertInstruction

All Superinterfaces:
  `ClassFileElementPREVIEW`, `CodeElementPREVIEW`, `InstructionPREVIEW`

public sealed interface ConvertInstruction extends InstructionPREVIEW
`ConvertInstruction` is a preview API of the Java platform.
Programs can only use `ConvertInstruction` when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Models a primitive conversion instruction in the `code` array of a `Code` attribute, such as `i2l`. Corresponding opcodes will have a `kind` of `Opcode.Kind.CONVERT`PREVIEW. Delivered as a `CodeElement`PREVIEW when traversing the elements of a `CodeModel`PREVIEW.

Since:
  22

- ## Method Summary

  Modifier and Type
  Method
  Description
  `TypeKindPREVIEW`
  `fromType()`
  Returns the source type to convert from.
  `static ConvertInstructionPREVIEW`
  `of(OpcodePREVIEW op)`
  Returns a conversion instruction.
  `static ConvertInstructionPREVIEW`
  `of(TypeKindPREVIEW fromType, TypeKindPREVIEW toType)`
  Returns A conversion instruction.
  `TypeKindPREVIEW`
  `toType()`
  Returns the destination type to convert to.

  ### Methods declared in interface java.lang.classfile.InstructionPREVIEW

  `opcode, sizeInBytes`

- ## Method Details

  - ### fromType

    TypeKindPREVIEW fromType()
    Returns the source type to convert from.
    Returns:
      the source type to convert from

  - ### toType

    TypeKindPREVIEW toType()
    Returns the destination type to convert to.
    Returns:
      the destination type to convert to

  - ### of

    static ConvertInstructionPREVIEW of(TypeKindPREVIEW fromType, TypeKindPREVIEW toType)
    Returns A conversion instruction.
    Parameters:
      `fromType` - the type to convert from
      `toType` - the type to convert to
    Returns:
      A conversion instruction

  - ### of

    static ConvertInstructionPREVIEW of(OpcodePREVIEW op)
    Returns a conversion instruction.
    Parameters:
      `op` - the opcode for the specific type of conversion instruction, which must be of kind `Opcode.Kind.CONVERT`PREVIEW
    Returns:
      a conversion instruction
    Throws:
      `IllegalArgumentException` - if the opcode kind is not `Opcode.Kind.CONVERT`PREVIEW.