Check whether object is of given type
In bytecode, immediately following the checkcast opcode is a 16-bit unsigned short integer. This integer is the index of an entry in the constant pool of the current class. The entry is tagged a CONSTANT_Class entry. The name field of the CONSTANT_Class entry is the same as the string given by <type> parameter in Jasmin.
Type | Description |
u1 | checkcast opcode = 0xE0 (224) |
u2 | index |
Stack ..., objectref => ..., objectref
checkcast checks that the top item on the operand stack (a reference to an object or array) can be cast to a given type.
The objectref must be of type reference
.
The index is an index into the constant pool of the constant pool entry of reference to a class, array, or interface type.
If objectref is null
or can be cast to the
resolved class, array, or interface type, the operand stack is unchanged; otherwise, the checkcast
instruction throws a ClassCastException
.
ClassCastException - the object on the stack is not an instance of the specified class
The opcode of this instruction was originally checkcast. The operands of the checkcast instruction are not modified.
The checkcast_quick instruction is very similar to the instanceof_quick
instruction. It differs in its treatment of null
, its behavior when its test
fails (checkcast_quick throws an exception, instanceof_quick pushes a result
code), and its effect on the operand stack.