ArrayRankNotPartOfType
DRAFT

Misconception:

One can assign an array with an arbitrary number of dimensions to a multi-dimensional array (e.g., int[][][] a = new int[1][1]; is ok).

Incorrect

The rank of an array is not part of its type

Correct

The rank of an array is part of its type

Correction
Here is what's right.

The type of an array includes the rank (the number of dimensions, the depth of array nesting). E.g., the type of a two-dimensional array of int is different from the type of a three-dimensional array of int (int[][] and int[][][] are different types).

Thus, the following is illegal:

int[][][] a = new int[1][1][1];
a[0] = new int[1]; // type error
// a[0] has type int[][]
// new int[1] has type int[]

Language

Java

Concepts

Related Misconceptions

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.