Interface ConstantInstruction
- All Superinterfaces:
ClassFileElement
,CodeElement
,Instruction
- All Known Subinterfaces:
ConstantInstruction.ArgumentConstantInstruction
,ConstantInstruction.IntrinsicConstantInstruction
,ConstantInstruction.LoadConstantInstruction
public sealed interface ConstantInstruction
extends Instruction
permits ConstantInstruction.IntrinsicConstantInstruction, ConstantInstruction.ArgumentConstantInstruction, ConstantInstruction.LoadConstantInstruction
Models a constant-load instruction in the
code
array of a
Code
attribute, including "intrinsic constant" instructions (e.g.,
iconst_0
), "argument constant" instructions (e.g., bipush
), and "load
constant" instructions (e.g., LDC
). Corresponding opcodes will have
a kind
of Opcode.Kind.CONSTANT
. Delivered as a CodeElement
when traversing the elements of a CodeModel
.- Since:
- 24
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Models an "argument constant" instruction (e.g.,bipush
).static interface
Models an "intrinsic constant" instruction (e.g.,iconst_0
).static interface
Models a "load constant" instruction (e.g.,ldc
). -
Method Summary
Modifier and TypeMethodDescriptionReturns the constant value.ofArgument
(Opcode op, int value) Returns an argument constant instruction.ofIntrinsic
(Opcode op) Returns an intrinsic constant instruction.ofLoad
(Opcode op, LoadableConstantEntry constant) Returns a load constant instruction.typeKind()
Returns the type of the constant.Methods declared in interface java.lang.classfile.Instruction
opcode, sizeInBytes
-
Method Details
-
constantValue
-
typeKind
-
ofIntrinsic
Returns an intrinsic constant instruction.- Parameters:
op
- the opcode for the specific type of intrinsic constant instruction, which must be of kindOpcode.Kind.CONSTANT
- Returns:
- an intrinsic constant instruction
- Throws:
IllegalArgumentException
- if the opcode does not represent a constant with implicit value
-
ofArgument
Returns an argument constant instruction.- Parameters:
op
- the opcode for the specific type of argument constant instruction, which must beOpcode.BIPUSH
orOpcode.SIPUSH
value
- the constant value- Returns:
- an argument constant instruction
- Throws:
IllegalArgumentException
- if the opcode is notOpcode.BIPUSH
orOpcode.SIPUSH
, or if the constant value is out of range for the opcode
-
ofLoad
static ConstantInstruction.LoadConstantInstruction ofLoad(Opcode op, LoadableConstantEntry constant) Returns a load constant instruction.- Parameters:
op
- the opcode for the specific type of load constant instruction, which must be of kindOpcode.Kind.CONSTANT
constant
- the constant value- Returns:
- a load constant instruction
- Throws:
IllegalArgumentException
- if the opcode is notOpcode.LDC
,Opcode.LDC_W
, orOpcode.LDC2_W
-