java Java标签语句和goto
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6650343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java label statement and goto
提问by Ismail Marmoush
Possible Duplicate:
goto keyword in java
可能的重复:
java 中的 goto 关键字
- There is no goto in java, right ?
- Why goto is still considered a keyword then ?
- Label syntax (only properly* used before a loop/if statement ?? ) and called through (label, break label, continue label)
- java中没有goto,对吧?
- 为什么 goto 仍然被认为是一个关键字呢?
- 标签语法(仅在循环/if 语句 ?? 之前正确*使用)并通过(标签、中断标签、继续标签)调用
*properly cause when i used before x=3
it couldn't be read after it are there any other cases ?
*正确原因当我之前使用x=3
它之后无法读取它还有其他情况吗?
int x = 2;
label: x = 3;
for (int j = 0; j < 5; j++) {
System.out.println(j);
}
label; // Compile error (no local variable label)
回答by Jon Skeet
From section 3.9 of the JLS:
The keywords
const
andgoto
are reserved, even though they are not currently used. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs.
关键字
const
andgoto
是保留的,即使它们当前未使用。如果这些 C++ 关键字错误地出现在程序中,这可能允许 Java 编译器生成更好的错误消息。
回答by Jigar Joshi
回答by Pablo Grisafi
1 - There is no goto in Java (the language), there is goto in Java (the virtual machine)
2 - The keywords const and goto are reserved, even though they are not currently used. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs. (from The java language specification)
3 - what is the question?
1 - Java(语言)中没有 goto,Java(虚拟机)中有 goto
2 - 关键字 const 和 goto 是保留的,即使它们当前未使用。如果这些 C++ 关键字错误地出现在程序中,这可能允许 Java 编译器生成更好的错误消息。(来自Java 语言规范)
3 - 问题是什么?
Anyway, read the The java language specification several times before going to SCJP (isn't OCJP now? )
反正去SCJP之前多读几遍Java语言规范(现在不是OCJP了吗?)