Java allows this:
class X{
int i,j[]; // j is an array, i is not
}
and even worse, it allows this:
class X{
int foo(String bar)[][][] // foo actually returns int[][][]
{ return null; }
}
Okay, the reason for this might be that it was lent from C/C++. However, Java meant to be easier than C/C++. Why did the Java inventors decide to allow this hard-to-read construct. The convoluted types of C where the variable name is in the middle of the type are just hard to read and provoke programming errors.
Especially the brackets behind the method signature. I have never seen these in use and that is for a good reason. No one looks behind the signature when checking the return type of a method. While the first example may save some keystrokes (because int does not have to be written twice), the brackets behind the signature do not even save any, so I see absolutely no gain here.
So is there a good reason for this (especially the second one) that I am missing?
foo[i], I'd argue declaring arrays asint foo[]makes a hell of a lot more sense than other ways around. It's also entirely clear which variable is an array, whileint[] foo, baris not. (Is it justfooor are both of them arrays?) – Izkata May 13 '14 at 03:26type name, name, ...;and when you have prefix "type operators" like*in C, you need operator precedence for them which increases ambiguity (int *is[]vsint (*ps)[]). – May 13 '14 at 11:47