Contents | Prev | Next | Index

checkcast

Operation
Check whether object is of given type

checkcast
indexbyte1
indexbyte2

Forms
checkcast = 192 (0xc0)

Stack
..., objectref ..., objectref

Description
The objectref must be of type reference. The unsigned indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The constant pool item at the index must be a CONSTANT_Class (§4.4.1), a symbolic reference to a class, array, or interface type. The symbolic reference is resolved (§5.1).

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.

The following rules are used to determine whether an objectref that is not null can be cast to the resolved type: if S is the class of the object referred to by objectref and T is the resolved class, array, or interface type, checkcast determines whether objectref can be cast to type T as follows:


Contents | Prev | Next | Index

Java Virtual Machine Specification (HTML generated by dkramer on February 25, 1997)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com