Write such a piece of code:
Copy codeThe Code is as follows: int I;
{
Int j = 1;
I = j;
}
If this code exists in the class definition area, we know that it is a common statement block used to initialize class attributes. It will be called during class instantiation, you can execute some methods.
In many instances, it is used in the singleton and other modes. Previously, a static file is added to initialize complex class content, which can avoid runtime exceptions caused by loading sequence.
But what if this code appears in the method?
It has no meaning at all. In my previous thought, it was a format that included the code.
Today I wrote a bit of Code related to the "Statement tag:Copy codeThe Code is as follows: label17: int I;
Int j;
ThreadGroup [] arrayOfThreadGroup;
If (flag)
Break label17;
Return 0;
"Syntax error on token": ", {expected after this token" exception occurred at the ":" location ".
That is to say, when the Code cannot exist in a single line (int I must have a clear instantiation/assignment position inside the method body), label17 needs to be marked with statement blocks.
The correct format is:Copy codeThe Code is as follows: label17 :{
Int I;
Int j;
ThreadGroup [] arrayOfThreadGroup;
If (flag)
Break label17;
Return 0;
}
Or:
Label17:
Int I;
Int j;
ThreadGroup [] arrayOfThreadGroup;
If (flag ){
Break label17;
Return 0 ;}
Let's take a look at the incorrect usage:Copy codeThe Code is as follows: label13: int x = 0;
Obviously, there is a default single-line statement block after the tag. This x cannot be used at any position in the future. It is incorrect. The prompt is as follows:
Multiple markers at this line
-X cannot be resolved to a variable
-Syntax error on token "int", delete this token
There are two correct formats:Copy codeThe Code is as follows: int x = 0;
Label13: x = 0;
Or
Label13: {int x = 0 ;}
Therefore, we assume that the logic if () is () and statement block {} should be independent of each other.