java - "immediately completes normally"对 if 语句意味着什么?

标签 java if-statement break java-11

“立即正常完成”是否意味着实际上绕过了 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 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.

其中 break 目标是一个 if 语句,然后封闭的标记语句是 if 语句并且它的条件已经被评估,因为你在它的体内,它的 contained Statement。它不会在完成 时再次计算。

关于java - "immediately completes normally"对 if 语句意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55833970/

相关文章:

java - SXSSFWorkbook(.xlsx文件)在mac上无法正确查看

java - firstLast Java链表/节点

javascript if 条件检查带换行符的字符串,即\n

python - 尝试将 True/False 值返回到 python 中的定义时出错

javascript - 在 Ruby 中重写 JavaScript break-to-label

c - 区分c中的0和0.0作为while循环的中断条件

java - Spring Autowiring 不适用于简单的类,但可以在其他地方使用

java - Java 中的 10 gig 以太网?

c++ - if-else语句无法正常工作的怪异错误

c# - 如果值存在;不要输入值。 if 语句