anewarray


Operation Create new array

anewarray
indexbyte1
indexbyte2


of reference

Forms anewarray = 189 (0xbd)

Stack ..., count ..., arrayref

Description The count must be of type int. It is popped off the operand stack. The count represents the number of components of the array to be created. The unsigned indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The item at that index in the constant pool must be tagged CONSTANT_Class (§4.4.1), a symbolic reference to a class, array, or interface type. The symbolic reference is resolved (§5.1). A new array with components of that type, of length count, is allocated from the garbage-collected heap, and a reference arrayref to this new array object is pushed onto the operand stack. All components of the new array are initialized to null, the default value for reference types (§2.5.1).

Linking Exceptions During resolution of the CONSTANT_Class constant pool item, any of the exceptions documented in §5.1 can be thrown.

Runtime Exception Otherwise, if count is less than zero, the anewarray instruction throws a NegativeArraySizeException.

Notes The anewarray instruction is used to create a single dimension of an array of object references. It can also be used to create part of a multidimensional array.