Working in Java
, what is the difference between using
Object[] variableName;
and using:
Object variableName[];
Does it have the exact same effect on compilation and run? Or is there a difference?
Working in Java
, what is the difference between using
Object[] variableName;
and using:
Object variableName[];
Does it have the exact same effect on compilation and run? Or is there a difference?
The statements will compile to the same code, BUT if you write
Type[] name
instead of Type name[]
the code becomes more readable, because you always can see the type (Array or Not-Array) in front of the variable name. (In fact this is some kind of my ppersonal meaning)
From Java language specification (for Java 7) :
The [] may appear as part of the type at the beginning of the declaration, or as part of the declarator for a particular variable, or both.
So yes, they are both equivalent and you can even mix the two styles in the same declaration (although the specification gives a healthy reminder to us that that tends to get ugly and confusing).