Only x, y and y1 will be in the String constant pool. For y2 Java will create a new Stirng object in normal memory, because "y1 +"b"" is not a compile-time constant expression. The String constant pool is for String literals only. See
JLS:
15.18.1 String Concatenation Operator +
If only one operand expression is of type String, then string conversion is performed on the other operand to produce a string at run time. The result is a reference to a String object (newly created, unless the expression is a compile-time constant expression (�15.28))that is the concatenation of the two operand strings.
[ January 31, 2008: Message edited by: Irina Goble ]
[ January 31, 2008: Message edited by: Irina Goble ]