Thread: Arrays in java
View Single Post
  #9 (permalink)  
Old 07-09-2012, 11:14 PM
Lew
Guest
 
Posts: n/a
Default Re: Arrays in java

Daniel Pitts wrote:
> Here is one that'll blow your mind:
>
> int[] arr[] = {{},{1},{2,3},{4,5,6}};
>
> I'm guessing you could even do 'int[] []arr[]';


Yes, but the JLS strongly discourages that.

“Brackets are allowed in declarators as a nod to the tradition of C and C++. The general rules for variable declaration, however, permit brackets toappear on both the type and in declarators, so that the local variable declaration:

“ float[][] f[][], g[][][], h[]; // Yechh!

“We do not recommend "mixed notation" in an array variable declaration, where brackets appear on both the type and in declarators.”

<http://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html#jls-10.2>

Know. Don't guess. Read the JLS.

Chant 12 times until it's ingrained in your subconscious.

--
Lew

Reply With Quote