ClassFileElement, CodeElement, Instructionpublic sealed interface TypeCheckInstruction extends Instruction
instanceof or a checkcast instruction in the code array of a Code attribute. Corresponding opcodes have a kind of Opcode.Kind.TYPE_CHECK. Delivered as a CodeElement when traversing the elements of a CodeModel. An instanceof checks the type and pushes an integer to the operand stack. A checkcast checks the type and throws a ClassCastException if the check fails. instanceof treat the null reference as a failure, while checkcast treat the null reference as a success.
A type check instruction is composite:
TypeCheckInstruction(
Opcode opcode,
ClassEntry type
)
| Modifier and Type | Method | Description |
|---|---|---|
static TypeCheckInstruction |
of |
Returns a type check instruction. |
static TypeCheckInstruction |
of |
Returns a type check instruction. |
ClassEntry |
type() |
Returns the type against which the instruction checks. |
opcode, sizeInBytes
ClassEntry type()
static TypeCheckInstruction of(Opcode op, ClassEntry type)
op - the opcode for the specific type of type check instruction, which must be of kind Opcode.Kind.TYPE_CHECK
type - the type against which to check or castIllegalArgumentException - if the opcode kind is not Opcode.Kind.TYPE_CHECK
static TypeCheckInstruction of(Opcode op, ClassDesc type)
op - the opcode for the specific type of type check instruction, which must be of kind Opcode.Kind.TYPE_CHECK
type - the type against which to check or castIllegalArgumentException - if the opcode kind is not Opcode.Kind.TYPE_CHECK, or if type is primitive
© 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/TypeCheckInstruction.html