我对此感到困惑。我们大多数人都听说过Java中没有goto语句。
但我发现它是Java中的关键字之一。它可以在哪里使用?如果它不能使用,那么为什么它作为关键字包含在Java中?
我对此感到困惑。我们大多数人都听说过Java中没有goto语句。
但我发现它是Java中的关键字之一。它可以在哪里使用?如果它不能使用,那么为什么它作为关键字包含在Java中?
当前回答
请参阅下面的链接,它显示了所有java保留字,并告诉您添加了哪些版本。
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html
Goto是保留的,即使目前没有使用,但永远不要说永远:)
其他回答
不,没有使用goto,但是您可以定义标签并留下一个到标签的循环。您可以使用break或continue后跟标签。所以你可以跳出多个循环层。看看教程。
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html
关键字const和goto是 矜持,尽管事实并非如此 目前使用。”
因为尽管Java语言不使用它,但JVM字节码使用它。
请注意,您可以将goto的大多数良性用途替换为by
返回 打破 打破标签 扔进去,试着抓住,最后
它们被保留以供将来使用(请参阅:Java语言关键字)
关键字const和goto是保留的,即使它们目前没有被使用。
Java中没有goto语句的原因可以在“Java语言环境”中找到:
Java has no goto statement. Studies illustrated that goto is (mis)used more often than not simply "because it's there". Eliminating goto led to a simplification of the language--there are no rules about the effects of a goto into the middle of a for statement, for example. Studies on approximately 100,000 lines of C code determined that roughly 90 percent of the goto statements were used purely to obtain the effect of breaking out of nested loops. As mentioned above, multi-level break and continue remove most of the need for goto statements.