Array Initialization using { } in Java

Viewed 748

We can initialize an array like this:

int myArray[][] = { {10,20} ,{30,40} , {50} };

It works fine.

But I came across a peculiar situation.

int myAnotherArray[][] = { {,} ,{,} , {,} };

The above line of code compiles fine. This according to me is weird. Because when the compiler would parse this statement , it would encounter { and , and } all together. Shouldn't the compiler be expecting a constant or a literal in between ? I would appreciate it if someone would tell me how exactly the above statement is parsed and what exactly the compiler does when it encounters such a situation.

1 Answers
Related