Package Summary Overview Summary

Module java.base
Package java.lang.classfile.instructionPREVIEW

# Interface ConstantInstruction

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

All Known Subinterfaces:
  `ConstantInstruction.ArgumentConstantInstructionPREVIEW`, `ConstantInstruction.IntrinsicConstantInstructionPREVIEW`, `ConstantInstruction.LoadConstantInstructionPREVIEW`

public sealed interface ConstantInstruction extends InstructionPREVIEW permits ConstantInstruction.IntrinsicConstantInstructionPREVIEW, ConstantInstruction.ArgumentConstantInstructionPREVIEW, ConstantInstruction.LoadConstantInstructionPREVIEW
`ConstantInstruction` is a preview API of the Java platform.
Programs can only use `ConstantInstruction` 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 constant-load instruction in the `code` array of a `Code` attribute, including "intrinsic constant" instructions (e.g., `iconst_0` ), "argument constant" instructions (e.g., `bipush`), and "load constant" instructions (e.g., `LDC`). Corresponding opcodes will have a `kind` of `Opcode.Kind.CONSTANT`PREVIEW. Delivered as a `CodeElement`PREVIEW when traversing the elements of a `CodeModel`PREVIEW.

Since:
  22

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Interface
  Description
  `static interface`
  `ConstantInstruction.ArgumentConstantInstructionPREVIEW`
  Preview.
  Models an "argument constant" instruction (e.g., `bipush` ).
  `static interface`
  `ConstantInstruction.IntrinsicConstantInstructionPREVIEW`
  Preview.
  Models an "intrinsic constant" instruction (e.g., `iconst_0` ).
  `static interface`
  `ConstantInstruction.LoadConstantInstructionPREVIEW`
  Preview.
  Models a "load constant" instruction (e.g., `ldc` ).

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ConstantDesc`
  `constantValue()`
  Returns the constant value.
  `static ConstantInstruction.ArgumentConstantInstructionPREVIEW`
  `ofArgument (OpcodePREVIEW op, int value)`
  Returns an argument constant instruction.
  `static ConstantInstruction.IntrinsicConstantInstructionPREVIEW`
  `ofIntrinsic (OpcodePREVIEW op)`
  Returns an intrinsic constant instruction.
  `static ConstantInstruction.LoadConstantInstructionPREVIEW`
  `ofLoad (OpcodePREVIEW op, LoadableConstantEntryPREVIEW constant)`
  Returns a load constant instruction.
  `TypeKindPREVIEW`
  `typeKind()`
  Returns the type of the constant.

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

  `opcode, sizeInBytes`

- ## Method Details

  - ### constantValue

    ConstantDesc constantValue()
    Returns the constant value.
    Returns:
      the constant value

  - ### typeKind

    TypeKindPREVIEW typeKind()
    Returns the type of the constant.
    Returns:
      the type of the constant

  - ### ofIntrinsic

    static ConstantInstruction.IntrinsicConstantInstructionPREVIEW ofIntrinsic (OpcodePREVIEW op)
    Returns an intrinsic constant instruction.
    Parameters:
      `op` - the opcode for the specific type of intrinsic constant instruction, which must be of kind `Opcode.Kind.CONSTANT`PREVIEW
    Returns:
      an intrinsic constant instruction

  - ### ofArgument

    static ConstantInstruction.ArgumentConstantInstructionPREVIEW ofArgument (OpcodePREVIEW op, int value)
    Returns an argument constant instruction.
    Parameters:
      `op` - the opcode for the specific type of intrinsic constant instruction, which must be of kind `Opcode.Kind.CONSTANT`PREVIEW
      `value` - the constant value
    Returns:
      an argument constant instruction

  - ### ofLoad

    static ConstantInstruction.LoadConstantInstructionPREVIEW ofLoad (OpcodePREVIEW op, LoadableConstantEntryPREVIEW constant)
    Returns a load constant instruction.
    Parameters:
      `op` - the opcode for the specific type of load constant instruction, which must be of kind `Opcode.Kind.CONSTANT`PREVIEW
      `constant` - the constant value
    Returns:
      a load constant instruction