public class SomeClass{
public static void main (String[] args){
if(true) int a = 0;// this is being considered as an error
if(true){
int b =0;
}//this works pretty fine
}
}//end class
在上面的类中,首先 if 语句显示编译错误
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token "int", delete this token
a cannot be resolved to a variable
但是第二个 if 语句工作正常。我只是无法自己弄清楚。我知道在单个语句中声明变量是没有用的if
。这两种说法有何不同,有人可以解释一下。对不起,如果问题真的很简单。