add a string to a string - What are the special places when strings are stitched together?
at compile time and run time this What is the character of a string for 2 periods?
1, String s = "S1";
String S1 = "S" +1;
System.out.println (S=S1);
Run Result: true
Compile period, you can determine s 1 -- because s 1 is also a constant. At compile time, s 1 Span style= "font-family: ' Times New Roman '" >1 .
so, when output, s 1 object is not created, directly pointing to the s refers to this object.
2,String s = "S1";
int SS = 1;
String S1 = "S" +SS;
System.out.println (S=S1);
Run Result: false
S and SS The value can be determined at compile time, but s 1 The value cannot be determined.
for s 1 this statement, ss -- The variable must not be determined at run time until its value is run to ss 1 The value is not determined until after the run time.
Conclusion: Can determine its value at compile time, "= "; The compilation period cannot be determined by its value, not" = ".
3,String c = "C1";
final int cc = 1;
String C1 = "C" +CC;
System.out.println (C=C1);
Run Result: true
at compile time,c,cc,c1 CC final cc this variable is 1 to replace it.
4, String d = "D1";
Final int dd = GETDD ();
String D1 = "D" +DD;
System.out.println (D=D1);
public static int GETDD () {
return 1;
}
Run Result:false
"=" is compared to "memory address" for an object.
AlthoughDD is final before theexecution of this sentence, the method can have a return value, that is, the runtime to determine its value, so the compilation period is not determined by the DD value of the.
Compile and run time analysis of String class