Compiler doesn't complain when I ended a line with two semicolons. Why?

后端 未结 7 2176
不思量自难忘°
不思量自难忘° 2021-01-19 01:29

I thought bad thing would happen when I ended a line like this. But compiler didn\'t even complain. Does anybody have an idea, why this is legal in java.

displ

相关标签:
7条回答
  • 2021-01-19 02:12

    It's an empty statement and is valid. As pointed out by jwodder, to be more precise the empty statement is the lack of statement between the two semicolon and could be represented by two consecutive semicolons or by semicolons separated by white space (that is including new lines).

    IDE like Eclipse will warn you about this. If you check the picture below, I've inserted a double semicolon on line 236. The red lines were added by me to focus the attention, but Eclipse give many visual cues:

    • a jagged yellow line under the semicolons.
    • a light bulb with a warning sign on the left margin of line 236, by hovering on that line, it will popup a small message saying "Unnecessary semicolon".
    • on the bar containing the directories and packages, the warning sign is shown again. It is shown for every package or source folder, which contains at least one warning.
    • on the package explorer and on the navigator file icon the same light bulb icon will be shown (not in this screenshot).

    enter image description here

    0 讨论(0)
提交回复
热议问题