I mistakenly declared an array of strings as follows:
String[] tokens[];
Eclipse does not highlight this as an error but instead considers it to be equivalent to:
String[][] tokens;
Is this correct behavior or a bug?
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.
It’s correct behaviour – arrays can be defined with brackets after either the object type or variable name.
and
are the same. It is however a confusing way to write a 2D array so I wouldn’t deliberately use it 😉
If you think of arrays as Objects (Which they technically are) and the square brackets as syntactic sugar for the new keyword and an empty contructor you could envisage your “error” as:
as both
and
would both be equivalent to