ClassFileElement, CodeElement, InstructionConstantInstruction.ArgumentConstantInstruction, ConstantInstruction.IntrinsicConstantInstruction, ConstantInstruction.LoadConstantInstructionpublic sealed interface ConstantInstruction extends Instruction permits ConstantInstruction.IntrinsicConstantInstruction, ConstantInstruction.ArgumentConstantInstruction, ConstantInstruction.LoadConstantInstruction
code array of a
Code attribute, including "intrinsic", "argument", and "load" constant instructions. Corresponding opcodes have a kind of Opcode.Kind.CONSTANT. Delivered as a CodeElement when traversing the elements of a CodeModel. The loaded constant value is symbolically represented as a ConstantDesc:
ConstantInstruction(ConstantDesc constantValue)
| Modifier and Type | Interface | Description |
|---|---|---|
static interface |
ConstantInstruction.ArgumentConstantInstruction |
Models an "argument constant" instruction, which encodes the constant value in the instruction directly. |
static interface |
ConstantInstruction.IntrinsicConstantInstruction |
Models an "intrinsic constant" instruction, which encodes the constant value in its opcode. |
static interface |
ConstantInstruction.LoadConstantInstruction |
Models a "load constant" instruction, which encodes the constant value in the constant pool. |
| Modifier and Type | Method | Description |
|---|---|---|
ConstantDesc |
constantValue() |
Returns the constant value. |
static ConstantInstruction.ArgumentConstantInstruction |
ofArgument |
Returns an argument constant instruction. |
static ConstantInstruction.IntrinsicConstantInstruction |
ofIntrinsic |
Returns an intrinsic constant instruction. |
static ConstantInstruction.LoadConstantInstruction |
ofLoad |
Returns a load constant instruction. |
TypeKind |
typeKind() |
Returns the computational type of the constant. |
opcode, sizeInBytes
ConstantDesc constantValue()
TypeKind typeKind()
constantValue.static ConstantInstruction.IntrinsicConstantInstruction ofIntrinsic(Opcode op)
op - the opcode for the specific type of intrinsic constant instruction, which must be of kind Opcode.Kind.CONSTANT
IllegalArgumentException - if the opcode does not represent a constant with implicit valuestatic ConstantInstruction.ArgumentConstantInstruction ofArgument(Opcode op, int value)
value must be in the range of byte, [-128, 127], for Opcode.BIPUSH, and in the range of short,
[-32768, 32767], for Opcode.SIPUSH.
op - the opcode for the specific type of argument constant instruction, which must be Opcode.BIPUSH or Opcode.SIPUSH
value - the constant valueIllegalArgumentException - if the opcode is not Opcode.BIPUSH or Opcode.SIPUSH, or if the constant value is out of range for the opcodestatic ConstantInstruction.LoadConstantInstruction ofLoad(Opcode op, LoadableConstantEntry constant)
op - the opcode for the specific type of load constant instruction, which must be of kind Opcode.Kind.CONSTANT
constant - the constant valueIllegalArgumentException - if the opcode is not Opcode.LDC, Opcode.LDC_W, or Opcode.LDC2_W
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/classfile/instruction/ConstantInstruction.html