---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 23 Edition"
java_version: 23
chapter: "Chapter 4. The class File Format"
section: "4.10.1.9.checkcast"
heading: "checkcast"
parent: "4.10.1.9. Type Checking Instructions"
source: https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.html#jvms-4.10.1.9.checkcast
id: "4.10.1.9.checkcast"
url: https://jvm.obfuscated.software/jvms/se23/4.10.1.9.checkcast.html
raw: https://jvm.obfuscated.software/jvms/se23/4.10.1.9.checkcast.md
---

# checkcast

A *checkcast* instruction with operand `CP` is type safe iff `CP` refers to a constant pool entry denoting either a class or an array, and one can validly replace the type `Object` on top of the incoming operand stack with the type denoted by `CP` yielding the outgoing type state.

```
instructionIsTypeSafe(checkcast(CP), Environment, _Offset, StackFrame,
                      NextStackFrame, ExceptionStackFrame) :-
    (CP = class(_, _) ; CP = arrayOf(_)),
    isBootstrapLoader(BL),
    validTypeTransition(Environment, [class('java/lang/Object', BL)], CP,
                        StackFrame, NextStackFrame),
    exceptionStackFrame(StackFrame, ExceptionStackFrame).
```
