当我用两个分号结束一行时,编译器不会抱怨。为什么? [英] Compiler doesn't complain when I ended a line with two semicolons. Why?

查看:208
本文介绍了当我用两个分号结束一行时,编译器不会抱怨。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我结束这样一条线时,我觉得会发生不好的事情。但编译器甚至没有抱怨。有没有人知道,为什么这在java中是合法的。

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.

displayDataMap.put(dateInterval,getDateInterval());;

编辑:Eclipse没有抱怨的原因是因为在 preference-> java - > compiler->错误/警告我有Empty语句:as ignore。

Edit: The reason Eclipse wasn't complaining was because in preference->java->compiler->Errors/Warning I had the Empty statement: as ignore.

推荐答案

这是一个空的陈述并且有效。正如jwodder所指出的,更确切地说,空语句是两个分号之间缺少语句,可以用两个连续的分号或用空格分隔的分号(包括新行)表示。

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).

像Eclipse这样的IDE会警告你这件事。如果您查看下面的图片,我在第236行插入了一个双分号。我添加了红线以集中注意力,但Eclipse提供了许多视觉提示:

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:


  • 分号下面的锯齿状黄线。

  • 一个灯泡,在236行的左边缘有一个警告标志,悬停在该行上,它将在包含目录和包的栏上弹出一条小消息不必要的分号。

  • ,再次显示警告标志。它显示在每个包或源文件夹中,其中包含至少一个警告。

  • 在包浏览器和导航器文件图标上将显示相同的灯泡图标(不在此处截图)。

  • 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).

这篇关于当我用两个分号结束一行时,编译器不会抱怨。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆