private String[][] var[]
This code compiles. But shouldn’t they make the array on type or variable?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The code is the same as this:
All these forms are equivalent:
And they all mean the same: a three-dimensional array of strings. The
String var[][][]syntax may seem a bit weird, but it’s like that for making C/C++ programmers feel right at home in Java (that’s how you normally declare an array type in C/C++).In Java, the
String[][][] varsyntax is preferred, as it makes clear that the type ofvarisString[][][], in the other syntax and its different variations the type information is split before and after the variable – although it’s perfectly legal from the compiler’s view point, it’s harder to read.Even weirder, all these method declarations are legal and equivalent: