参见英文答案 >
What is the use of an empty statement (not for loop) in Java? [closed] 6个
我知道分号需要用分号结尾,就像在这段代码中一样:
public class Main{
public static void main(String[] args){
System.out.println("blah blah blah and stuff")
}
}
在println语句的末尾需要分号,否则程序将无法编译.
最近,我偶然在println语句的末尾放了两个分号:
System.out.println("blah blah blah and stuff");;
我注意到了,所以我开始在我的程序中放置分号
public class Main{;;;;;;
public static void main(String[] args){;;;;;;;;
System.out.println("blah blah blah and stuff");;;;;;
};;;;;;
};;;;;
此代码编译,打印字符串,没有错误或意外结果.我已经搜索了为什么编译器似乎只是忽略了这些分号,但从未找到任何特别提及的内容.那么,为什么这些分号不会产生语法错误?