Contents | Prev | Next | Index

instanceof

Operation

instanceof
indexbyte1
indexbyte2
Determine if object is of given type

Forms
instanceof = 193 (0xc1)

Stack
..., objectref ..., result

Description
The objectref, which must be of type reference, is popped from the operand stack. 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 item at that index in the constant pool must be a CONSTANT_Class (§4.4.1), a symbolic reference to a class, array, or interface. The symbolic reference is resolved (§5.1).

If objectref is not null and is an instance of the resolved class, array, or interface, the instanceof instruction pushes an int result of 1 as an int on the operand stack. Otherwise, it pushes an int result of 0.

The following rules are used to determine whether an objectref that is not null is an instance of 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, instanceof determines whether objectref is an instance of 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