Java中是否有goto语句? [英] Is there a goto statement in Java?

查看:158
本文介绍了Java中是否有goto语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此感到困惑。我们大多数人都被告知Java中没有任何goto语句。

I'm confused about this. Most of us have been told that there isn't any goto statement in Java.

但我发现它是Java中的关键字之一。哪里可以使用?如果它不能使用,那么为什么它作为关键字包含在Java中?

But I found that it is one of the keywords in Java. Where can it be used? If it can not be used, then why was it included in Java as a keyword?

推荐答案

Java关键字列表指定 goto 关键字,但它被标记为未使用。

The Java keyword list specifies the goto keyword, but it is marked as "not used".

它位于原始JVM中(参见 @VitaliiFedorenko回答),但随后删除了。它可能保留为保留关键字,以防它被添加到更高版本的Java。

It was in the original JVM (see answer by @VitaliiFedorenko), but then removed. It was probably kept as a reserved keyword in case it were to be added to a later version of Java.

如果 goto 不在列表中,稍后会将其添加到语言中,现有代码使用单词 goto 作为标识符(变量名,方法名等)。 ..)会打破。但是因为 goto 是一个关键字,这样的代码甚至不能在当前编译,并且它仍然可以在以后实际执行某些操作,而不会破坏现有代码。

If goto was not on the list, and it gets added to the language later on, existing code that used the word goto as an identifier (variable name, method name, etc...) would break. But because goto is a keyword, such code will not even compile in the present, and it remains possible to make it actually do something later on, without breaking existing code.

这篇关于Java中是否有goto语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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