Sandra Bachan wrote:
Would really appreciate if someone can draw how this looks in memory, esp when s2 is final vs. non-final.
It's not a memory issue. It's a compiler issue.
A final
string referenced that is assigned during declaration to a string literal is a compile time constant. So... The s2 reference is a compile time constant. The sum of two compile time constants is a compile time constant. Hence, the assignment of the s3 reference is to a string that is a compile time constant, and hence, in the string pool. So... the first comparison is true.
While the s4 reference is pointing to a string that is in the string pool, the concat being done to be assigned the s5 reference is not done at compile time, and is not in the string pool. And hence... the second comparison is false.
Henry