I come across this code line in a book and it said this is legal , but I don’t really understand though having googling.
the code is:
Boolean [] ba [];
I just know that to create an array, it should be like this:
int [] numberArray;
int numberArray [];
int [] [] num2DArray;
Thanks!
All those 3 declarations have the same meaning in java :
I don’t really like it but as there aren’t any confusion possible, there is no very big harm in letting them be equivalent. The rationale was that C and C++ coders were used to a certain notation :
while the recommendation in java is to consistently declare the type before as in
Here’s the reference : http://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html#jls-10.2
And two extracts :
In order to be more readable in Java, I suggest you stick to the usual
Note that you have a similar behavior for method declarations. Here’s an excerpt from the
ByteArrayOutputStreamclass source code:This is allowed for compatibility but please don’t use that. Most coders at first sight wouldn’t notice the
[]and thus wouldn’t immediately read that this method returns an array.