# check-cast

## Purpose

Throw if the reference in the given register cannot be cast to the indicated type. The type must be a reference type (not a primitive type).

## Details

Op & Format | Mnemonic / Syntax | Arguments
--- | --- | ---
1f 21c | check-cast vAA, type@BBBB | `A:` reference-bearing register (8 bits) `B:` type index (16 bits)

## Constraints

- A must be a valid register index in the current stack frame.
- Register vA must contain a reference value.
- B must be a valid index into the type pool.
- Type pool entry B must contain a valid type descriptor for a reference type.

## Behavior

- An attempt is made to get a reference to the class C the name of which is contained in type pool entry B.
- If C has not been loaded and resolved before, it is being loaded and resolved. All exceptions that are possible during class loading can occur at this point.
- The run-time type of the object reference vA is compared against C.
  - If vA is null, the instruction succeeds (without further effects).
  - If vA is assignment compatible with C according to the usual rules of the Java programming language, the instruction succeeds (without further effects).

## Exceptions

- ClassCastException is thrown if vA is either not null or not assignment compatible with C.