Why is this Java array considered two dimensional?

arrays, java

Solution

Take this example:

int a, b;

Then both a and b are ints, right? So now take this:

int[] a, b;

The both a and b are int arrays. So by adding another set of brackets:

int[] a, b[];

you have added another set of brackets to b.

Either of these would be fine:

int[] a = null , b = null;
int a[] = null , b[] = null;

or as you say, simply putting them on separate lines would work too (and be much easier to read).

Problem

Consider this code: ``` class arraytest { public static void main(String args[]) { int[] a = null , b[] = null; b = a; System.out.println( b ); } } ``` The line ``` b = a; ``` is flagged by the compiler saying: ``` Incompatible types, found int[], required int [][] ``` Why is b considered two dimensional? I realize the "shortcut" declaration `int[] a = null , b[] = null;` is to blame, but why does it make the array two dimensional when only one set of brackets have been written? I find this syntax unclear and obfuscating.

Original source