“立即正常完成”是否意味着实际上绕过了 if 语句并且不评估其条件?
编辑:
为了理解 Java 规范中与 if 语句相关的短语 iteself,我特意省略了一个示例。
但似乎没有人在这种情况下考虑过这个短语。
所以这是一个演示程序。
import java.io.*;
class TestBreakWIthLabel
{
public static void main (String[] args) throws java.lang.Exception
{
int x = 1;
L:if ( x++ < 2 ) break L;
System.out.println( "x = " + x );
}
}
但是,如果有人会针对该程序提供他的“解释”,那可不是个好主意。我想独立于程序示例了解该短语的含义。
这是规范(14.15 中断语句)中的相应引用。
A break statement with label Identifier attempts to transfer control to the enclosing labeled statement (§14.7) that has the same Identifier as its label; this statement, which is called the break target, then immediately completes normally. In this case, the break target need not be a switch, while, do, or for statement.
最佳答案
假设您指的是 this part of the JLS
A
break
statement withlabel Identifier
attempts to transfer control to the enclosing labeled statement (§14.7) that has the sameIdentifier
as itslabel
; this statement, which is called thebreak
target, then immediately completes normally. In this case, thebreak
target need not be aswitch
,while
,do
, orfor
statement.
其中 break
目标是一个 if
语句,然后封闭的标记语句是 if
语句并且它的条件已经被评估,因为你在它的体内,它的 contained Statement。它不会在完成 时再次计算。
关于java - "immediately completes normally"对 if 语句意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55833970/