Is the tag a Java statement?

Whether the tag is a Java statement and whether the tag is a statement defined as a statement in the Java language specification?

My question relates to Jan lahoda's following reply in the error report I sent to Oracle I can't discuss it there because I can't get an account in openjdk JIRA

https://bugs.openjdk.java.net/browse/JDK-8211052

I think the tag in Java is not a statement. In Jan's example, both a and B tags are related to the same while loop statement, so compile time errors should not be triggered

Bonus:

Is it marked as / do / for statement in / while / do / for statement in Java?

Solution

After JLS, declare that you can

StatementWithoutTrailingSubstatement
LabeledStatement
IfThenStatement
IfThenElseStatement
WhileStatement
ForStatement

Same as labeledstatement

Identifier : Statement

And explain

So in the case of a loop

public void method() {
    loop1: loop2: while (true) {
        if (true) {
            break loop1;
        } else {
            continue loop1;
        }
    }
}

The label statement loop1 is the whole loop2

If we look at the definition of break, it shows that

And for continuing it

These definitions are consistent with the compiler, provide compiler errors for the continue loop1 statement, and make break loop1 valid because loop2:... Is not a "while, do, or for statement"

About your practical question: is the tag a Java declaration?

The following code is completely legal and well compiled

public void method() {
    loop:;
}

This follows the extension of statement – > Labeledstatement – > identifier: declaration – > loop: statement – > loop: statementwithtrailingsubstatement – > loop: emptystatement – >

loop : ;

No, the tag itself is not declared. The identifier (later called "tag") plus Colom plus emptystatement (;) However

Is there no tag / do / for statement in / A / do / for statement?

No, Labeledstatement is like this: labeledstatement A marked as declaration – > label – > identifier: declaration – > identifier: whilestatement is basically different from statement – > whilestatement!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>