gpt4 book ai didi

java - Java 中的标记语句 block ?

转载 作者:搜寻专家 更新时间:2023-10-30 21:44:35 24 4
gpt4 key购买 nike

当我发现一段代码被 scan:{} block 包围时,我正在浏览一些基本的 Java 对象。以下代码来自 String 类中的 toLowerCase() 方法。

scan: {
for (firstUpper = 0 ; firstUpper < len; ) {
char c = value[firstUpper];
if ((c >= Character.MIN_HIGH_SURROGATE)
&& (c <= Character.MAX_HIGH_SURROGATE)) {
int supplChar = codePointAt(firstUpper);
if (supplChar != Character.toLowerCase(supplChar)) {
break scan;
}
firstUpper += Character.charCount(supplChar);
} else {
if (c != Character.toLowerCase(c)) {
break scan;
}
firstUpper++;
}
}
return this;
}

有人可以解释一下 scan:{} block 的用途以及此语法的来源吗?除非在三元运算符中使用,否则我还没有在 Java 中看到像这样的单词后有冒号。

谢谢!

编辑:更新标题以正确匹配已回答的问题。

最佳答案

在这里,scan:只是一个label . break <label>语法允许跳出外部循环,并模拟某些形式的 goto陈述。语法记录在 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.

关于java - Java 中的标记语句 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14147821/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com