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

# anewarray

An *anewarray* instruction with operand `CP` is type safe iff `CP` refers to a constant pool entry denoting a class, interface, or array type, and one can legally replace a type matching `int` on the incoming operand stack with an array with component type `CP` yielding the outgoing type state.

```
instructionIsTypeSafe(anewarray(CP), Environment, _Offset, StackFrame,
                      NextStackFrame, ExceptionStackFrame) :-
    (CP = class(_, _) ; CP = arrayOf(_)),
    validTypeTransition(Environment, [int], arrayOf(CP),
                        StackFrame, NextStackFrame),
    exceptionStackFrame(StackFrame, ExceptionStackFrame).
```
