ldc :
push single-word constant onto stack : index : visitLdcInsn()
- Description
- ldc pushes a one-word constant onto the operand stack.
ldc takes a single parameter, <value>, which is
the value to push. The following Java types can be pushed using ldc:
int
float
String
Pushing a String causes a reference to a java.lang.String object to be
constructed and pushed onto the operand stack. Pusing an int or a float causes
a primitive value to be pushed onto the stack. - Exceptions
- OutOfMemoryError - not enough memory to allocate a reference to a
String
- Example
ldc "Hello World" ; push string "Hello World" onto stack
ldc 10 ; push the integer 10
ldc 1.54 ; push the single-precision float 1.54
- Notes
- 1. Where possible, its more efficient to use one of bipush,
sipush, or one of the const instructions instead of ldc.
2. If the same string constant (i.e. a string with the same sequence of
characters) appears in several different class files, only one String instance
is built for that constant. The String.intern() method can be used to retrieve
the instance used for a given sequence of characters. - See also
- bipush sipush ldc_w ldc2_w aconst_null iconst_m1 iconst_n lconst_l fconst_f dconst_d
- Stack
Before
|
After |
... |
<value> |
|
... |
- Bytecode
Type
|
Description |
u1
|
ldc
opcode = 0x12 (18)
|
u1
|
index |