---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 27 Edition"
java_version: 27
chapter: "Chapter 6. The Java Virtual Machine Instruction Set"
section: "6.5.instanceof"
heading: "instanceof"
parent: "6.5. Instructions"
source: https://docs.oracle.com/javase/specs/jvms/se27/html/jvms-6.html#jvms-6.5.instanceof
id: "6.5.instanceof"
url: https://jvm.obfuscated.software/jvms/se27/6.5.instanceof.html
raw: https://jvm.obfuscated.software/jvms/se27/6.5.instanceof.md
---

# instanceof

## 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](2.6.md)), 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](5.4.3.1.md)). 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*](6.5.checkcast.md).

## 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](5.4.3.1.md) can be thrown.

## Notes

The *instanceof* instruction is very similar to the *checkcast* instruction ([§*checkcast*](6.5.checkcast.md)). 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.
