Operation
Determine if object is of given type
Format
instanceof
indexbyte1
indexbyte2
Forms
instanceof = 193 (0xc1)
Operand 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 run-time constant pool of the current class (§2.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The run-time constant pool entry at the index must be a symbolic reference to a class, array, or interface type.
If objectref is null, the instanceof instruction pushes an int result of 0 onto the operand stack.
Otherwise, the named class, array, or interface type is resolved (§5.4.3.1). If objectref is a value of the type given by the resolved class, array, or interface type, the instanceof instruction pushes an int result of 1 onto the operand stack; otherwise, it pushes an int result of 0.
Whether objectref is a value of the type given by the resolved class, array, or interface type is determined according to the rules given for §checkcast.
Linking Exceptions
During resolution of the symbolic reference to the class, array, or interface type, any of the exceptions documented in §5.4.3.1 can be thrown.
Notes
The instanceof instruction is very similar to the checkcast instruction (§checkcast). It differs in its treatment of null, its behavior when its test fails (checkcast throws an exception, instanceof pushes a result code), and its effect on the operand stack.