加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

用Java标记语句块?

发布时间:2020-12-15 07:37:19 所属栏目:Java 来源:网络整理
导读:当我发现一段代码被scan:{}块包围时,我正在浏览一些基础 Java对象.以下代码来自String类中的toLowerCase()方法. scan: { for (firstUpper = 0 ; firstUpper len; ) { char c = value[firstUpper]; if ((c = Character.MIN_HIGH_SURROGATE) (c = Character.M
当我发现一段代码被scan:{}块包围时,我正在浏览一些基础 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:{}块用于什么以及此语法来自何处?除非在三元运算符中使用,否则我还没有在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读