iconst_0 or iconst_1 or iconst_2 or iconst_3 or iconst_4 or iconst_5Stack
Before | After |
... | <n> |
| ... |
iconst_<n> represents the series of opcodes iconst_0, iconst_1, iconst_2, iconst_3, iconst_4 and iconst_5. These are used to push the constant ints 0 through 5 onto the stack. For example, to push the int zero onto the stack, use:
iconst_0 ; push 0 onto the stack.Note that you could also use:
bipush 0 ; push 0 onto the stackor
sipush 0 ; push 0 onto the stackor
ldc 0 ; push 0 onto the stackalthough these instructions are typically less efficient than the equivalent iconst_<n> and also take up more bytes in the class file.
Example
iconst_0 ; push 0 onto the stack iconst_1 ; push 1 onto the stack iconst_2 ; push 2 onto the stack iconst_3 ; push 3 onto the stack iconst_4 ; push 4 onto the stack iconst_5 ; push 5 onto the stackBytecode
Type | Description |
u1 | iconst_0 opcode = 0x03 (3) |
u1 | iconst_1 opcode = 0x04 (4) |
u1 | iconst_2 opcode = 0x05 (5) |
u1 | iconst_3 opcode = 0x06 (6) |
u1 | iconst_4 opcode = 0x07 (7) |
u1 | iconst_5 opcode = 0x08 (8) |
bipush, sipush, ldc, ldc_w, ldc2_w, aconst_null, iconst_m1, lconst_<l>, fconst_<f>, dconst_<d>