Store object reference in the local variable
Bytecode
For local variable numbers in the range 0-255, use:
Type | Description |
u1 | astore opcode = 0x3A (58) |
u1 | <varnum> |
The astore opcode can be used in conjunction with the wide instruction to access a local variable using a two-byte unsigned index. There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description |
u1 | wide opcode = 0xC4 (196) |
u1 | astore opcode = 0x3A (58) |
u2 | <varnum> |
Pops objectref (a reference to an object or array) off the stack and stores it in local variable <varnum>.
The astore instruction takes a single parameter, <varnum>, an unsigned integer which indicates which local variable is used. <varnum> must be a valid local variable number in the current frame.
The objectref on the top of the operand stack must be of type returnAddress
or of type reference
. It is popped from the operand stack, and the value of
the local variable at <varnum> is set to objectref.
The astore instruction is used with an objectref of
type returnAddress
when implementing Java's finally
keyword. The
aload instruction cannot be used to load a value of type returnAddress
from a local variable onto the operand stack. This asymmetry with the astore
instruction is intentional.