Like writing a piece of code like this:
Copy Code code as follows:
If this code exists in the class definition area, then we know that it is a normal statement block that initializes the contents of the class attribute, which is invoked when the class is instantiated, and it can execute some methods.
In many instances, it is used in singleton patterns, preceded by a static, to initialize content for complex classes, and to avoid some run-time exceptions due to the load sequence.
But what if the code appears in the method?
It has no meaning at all. In my own previous thoughts, it was a form of code, no other.
Today I wrote a bit of code related to the statement label:
Copy Code code as follows:
Label17:int i;
Int J;
Threadgroup[] Arrayofthreadgroup;
if (flag)
Break label17;
return 0;
":" The Exception "Syntax error on Token": ", {expected to this token."
In other words, when the code cannot exist in a single line (int I must have an explicit instantiation \ Assignment position within the method body), Label17 needs to be marked with a statement block.
The correct format is:
Copy Code code 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 look at the wrong usage:
Copy Code code as follows:
Obviously, there is a default one-line statement block after the label, and this x cannot be used anywhere in the future. The prompts are as follows:
Multiple markers at-line
-X cannot be resolved to a variable
-Syntax error on token ' int ', delete this token
There are two types of correct formats:
Copy Code code as follows:
int x = 0;
label13:x = 0;
Or
label13:{int x = 0;}
So it is inferred that a previous misunderstanding, for () {},if () {} usage, the logical if () and statement block {} should be two separate syntaxes.