我们在编写代码时,经常用到final关键字,这是java的保留字。
- 修饰类时,表明这个类不能被继承。
String a="hello2";
String b="hello"+2;
System.out.println("a==c--> "+(a==b));
String c="hello";
final String d="hello";
String e=c+2;
String f=d+2;
System.out.println("a==e--> "+(a==e));
System.out.println("a==f--> "+(a==f));
out:
a==c--> true
a==e--> false
a==f--> true
你们发现什么规律了?