Why does this first if compile well and the second fail?
if(proceed) {int i;} // This compiles fine.
if(proceed) int i;// This gives an error. (Syntax error on token ")", { expected after this token)
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.
Because the language spec says so:
http://docs.oracle.com/javase/specs/jls/se7/html/jls-6.html
Your first example is declaring
iinside a block (denoted by curly braces). Your second isn’t, nor is it aforstatement.Edited to add: Which just makes commons sense. If it were allowed, it would be useless. It would immediately fall out of scope.