I read this Questions about Java's String pool and understand the basic concept of string pool but still don\'t understand the behavior.
First: it works if you
The compiler can perform constant evaluation but not in the case where you modify the values
Try instead following and see what happens if you drop final
from either variable.
final String s1 = "abc";
final String s2 = "abc";
System.out.println("s1 == s2? " + (s1 == s2));
String s3 = s1 + "d";
String s4 = s2 + "d";
System.out.println("s3 == s4? " + (s3 == s4));