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

查看:35
本文介绍了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天全站免登陆