1.+号的优化
String str = "11"+ "22";
同理引申:
final String str2 = "12";
final String str3 = "34";
String str4 = str2 + str3;
String str5 = "1234";
System.out.println(str4 == str5);//有final为true,无final为false
编译器会优化成:
String str = "1122";
String str4 = "1234";
如果去掉final,将是另外一种结果
2.字段定义自动提到最上面
public class A {
static {
str = "3"
}
static String str = "4";
static{
System.out.println(str)
}
}
网友评论