为什么Java在语句结尾处不显示双分号错误? [英] Why does Java not show an error for double semicolon at the end of a statement?

查看:157
本文介绍了为什么Java在语句结尾处不显示双分号错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心写了一个带有两个分号的java语句。 java编译器没有显示任何错误,它会运行。

I accidentally wrote a java statement with two semicolons at the end. The java compiler does not show any error and it runs.

代码:

System.out.println("Length after delete the text is "+name.length());;

出于学习目的,我尝试在分号后添加不同的字符,java编译器显示了编译时间错误为令牌上的语法错误),删除此令牌

For learning purposes I tried adding different characters after the semicolon, and the java compiler has shown the compile time error as Syntax error on token ")", delete this token.

此声明:

System.out.println("Length after delete the text is "+name.length());)

为什么java将分号和其他字符视为不同?

Why does java treat the semicolon and other characters as different?

推荐答案

因为双分号不是双分号,而是分号加空语句。并且一个没有任何作用的空语句不是错误。

Because a double semicolon is not treated as a double semicolon but as a semicolon plus an empty statement. And an empty statement, which does nothing, is not an error.

这篇关于为什么Java在语句结尾处不显示双分号错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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