Interface ConstantInstruction
- All Superinterfaces:
ClassFileElementPREVIEW,CodeElementPREVIEW,InstructionPREVIEW
- All Known Subinterfaces:
ConstantInstruction.ArgumentConstantInstructionPREVIEW,ConstantInstruction.IntrinsicConstantInstructionPREVIEW,ConstantInstruction.LoadConstantInstructionPREVIEW
public sealed interface ConstantInstruction
extends InstructionPREVIEW
permits ConstantInstruction.IntrinsicConstantInstructionPREVIEW, ConstantInstruction.ArgumentConstantInstructionPREVIEW, ConstantInstruction.LoadConstantInstructionPREVIEW
ConstantInstruction is a preview API of the Java platform.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
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.CONSTANTPREVIEW. Delivered as a CodeElementPREVIEW when traversing the elements of a CodeModelPREVIEW.- Since:
- 22
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfacePreview.Models an "argument constant" instruction (e.g.,bipush).static interfacePreview.Models an "intrinsic constant" instruction (e.g.,iconst_0).static interfacePreview.Models a "load constant" instruction (e.g.,ldc). -
Method Summary
Modifier and TypeMethodDescriptionReturns the constant value.ofArgument(OpcodePREVIEW op, int value) Returns an argument constant instruction.Returns an intrinsic constant instruction.ofLoad(OpcodePREVIEW op, LoadableConstantEntryPREVIEW constant) Returns a load constant instruction.typeKind()Returns the type of the constant.Methods declared in interface java.lang.classfile.InstructionPREVIEW
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.CONSTANTPREVIEW- Returns:
- an intrinsic constant instruction
- Throws:
IllegalArgumentException- if the opcode does not represent a constant with implicit value
-
ofArgument
static ConstantInstruction.ArgumentConstantInstructionPREVIEW ofArgument(OpcodePREVIEW op, int value) Returns an argument constant instruction.- Parameters:
op- the opcode for the specific type of argument constant instruction, which must beOpcode.BIPUSHPREVIEW orOpcode.SIPUSHPREVIEWvalue- the constant value- Returns:
- an argument constant instruction
- Throws:
IllegalArgumentException- if the opcode is notOpcode.BIPUSHPREVIEW orOpcode.SIPUSHPREVIEW, or if the constant value is out of range for the opcode
-
ofLoad
static ConstantInstruction.LoadConstantInstructionPREVIEW ofLoad(OpcodePREVIEW op, LoadableConstantEntryPREVIEW constant) Returns a load constant instruction.- Parameters:
op- the opcode for the specific type of load constant instruction, which must be of kindOpcode.Kind.CONSTANTPREVIEWconstant- the constant value- Returns:
- a load constant instruction
- Throws:
IllegalArgumentException- if the opcode is notOpcode.LDCPREVIEW,Opcode.LDC_WPREVIEW, orOpcode.LDC2_WPREVIEW
-
ConstantInstructionwhen preview features are enabled.