NOTE: this question was previously marked as a duplicate. It's subtly different, though: the other question asked what the difference is between the two syntaxes; whereas I know there's no difference in meaning, and I'm asking in that case why Java allows both.
Why does Java allow both
int x[];
and
int[] x;
when I declare an array?
The latter makes much more sense: the variable is called x
, not x[]
, and its type is int[]
, not int
. Why not just enforce this? Allowing two different syntaxes seems just to invite confusion and inconsistency. It even appears to make it possible to declare a two-dimensional array as
int[] x[];
which is bordering on unreadable.
Is it something borrowed from C? (Why would C do it that way round, anyway?)