Silly question, but why does the following line compile?
int[] i = new int[] {1,};
As you can see, I haven’t entered in the second element and left a comma there. Still compiles even though you would expect it not to.
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.
I suppose because the ECMA 334 standard say:
As you can see, the trailing comma is allowed:
P.S. for a good answer (even if this fact was already pointed by many users). 🙂
Trailing comma could be used to ease the implementation of automatic code generators (generators can avoid to test for last element in initializer, since it should be written without the trailing comma) and conditional array initialization with preprocessor directives.