Java programming language is rarely understand the characteristics of people -statement label

The following statement will compile error or what to print?

        System.out.print("baidu site :");
        https://www.baidu.com;
        System.out.println(" format");

 

Many people will say: will compile error, the middle row is what the hell?

Java programming language is rarely understand the characteristics of people -statement label

 

In fact, does not complain, it will print out:

baidu site : format

If you change this statement, it is not it will not feel a compiler error?

        System.out.print("baidu site :");
        https :
            //www.baidu.com;
        System.out.println(" format");

 

A lot like a switch statement in the case

int q = (n+7)/8;
switch (n%8) {
 case 0: do { foo(); // Great C hack, Tom,
 case 7: foo(); // but it's not valid here.
 case 6: foo();
 case 5: foo();
 case 4: foo();
 case 3: foo();
 case 2: foo();
 case 1: foo();
 } while (--q > 0);
}

 

The above statement, ":" is translated into label statement label statement.

The syntax is as follows:

LabeledStatement:
Identifier : Statement
LabeledStatementNoShortIf:
Identifier : StatementNoShortIf

With different c and c ++, java no goto statement; statement to appear on the label anywhere within the continue statement or break statement label.

Again a standard sentence statement as at the end of practice it

class Test {
 char[] value;
 int offset, count;
 int indexOf(TestString str, int fromIndex) {
 char[] v1 = value, v2 = str.value;
 int max = offset + (count - str.count);
 int start = offset + ((fromIndex < 0) ? 0 : fromIndex);
 i:
 for (int i = start; i <= max; i++) {
 int n = str.count, j = i, k = str.offset;
 while (n-- != 0) {
 if (v1[j++] != v2[k++])
 continue i;
 } 
 return i - offset;
 }
 return -1;
 }
}

 

Reference material

【1】https://docs.oracle.com/javase/specs/jls/se12/html/jls-14.html#jls-14.7

Guess you like

Origin www.cnblogs.com/davidwang456/p/11505556.html