# Interface LoadInstruction

All Superinterfaces:
  `ClassFileElement`, `CodeElement`, `Instruction`

public sealed interface LoadInstruction extends Instruction
Models a local variable load instruction in the `code` array of a `Code` attribute. Corresponding opcodes have a kind of `Opcode.Kind.LOAD`. Delivered as a `CodeElement` when traversing the elements of a `CodeModel`.

A local variable load instruction is composite:

    LoadInstruction(
        TypeKind typeKind,
        int slot
    )

where `TypeKind` is computational, and `slot` is within `[0, 65535]`.

Since:
  24
See Also:
  - `Opcode.Kind.LOAD`
  - `CodeBuilder::loadLocal`

## Method Summary

Modifier and Type
Method
Description
`static LoadInstruction`
`of(Opcode op, int slot)`
Returns a local variable load instruction.
`static LoadInstruction`
`of(TypeKind kind, int slot)`
Returns a local variable load instruction.
`int`
`slot()`
Returns the local variable slot to load from.
`TypeKind`
`typeKind()`
Returns the computational type of the value to be loaded.

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

`opcode, sizeInBytes`

## Method Details

### slot

int slot()
Returns the local variable slot to load from. The value is within `[0, 65535]`.

Returns:
  the local variable slot to load from

### typeKind

TypeKind typeKind()
Returns the computational type of the value to be loaded.

Returns:
  the computational type of the value to be loaded

### of

static LoadInstruction of(TypeKind kind, int slot)
Returns a local variable load instruction. `kind` is converted to its computational type. `slot` must be within `[0, 65535]`.

Parameters:
  `kind` - the type of the value to be loaded
  `slot` - the local variable slot to load from
Returns:
  a local variable load instruction
Throws:
  `IllegalArgumentException` - if `kind` is `void` or `slot` is out of range

### of

static LoadInstruction of(Opcode op, int slot)
Returns a local variable load instruction.

The range of `slot` is restricted by the `op` and its size:

- If `op` has size 1, `slot` must be exactly the slot value implied by the opcode.
- If `op` has size 2, `slot` must be within `[0, 255]`.
- If `op` has size 4, `slot` must be within `[0, 65535]`.

API Note:
  The explicit `op` argument allows creating `wide` or regular load instructions when the `slot` can be encoded with more optimized load instructions.
Parameters:
  `op` - the opcode for the specific type of load instruction, which must be of kind `Opcode.Kind.LOAD`
  `slot` - the local variable slot to load from
Returns:
  a local variable load instruction
Throws:
  `IllegalArgumentException` - if the opcode kind is not `Opcode.Kind.LOAD` or `slot` is out of range