• Post Reply Bookmark Topic Watch Topic
  • New Topic

Constant Pool output doesn't match  RSS feed

 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have come across this question and i thought true should be printed in 2nd case as Strings in constant pool sharing same reference but it returns false.

 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your String s3 is not in the constant pool.

From the Java Language Specification section 15.8.1 (talking about the String Concatenation operator +):


The String object is newly created unless the expression is a constant expression.


Your expression 's1 + s2' is not a constant expression, so the result is a new String object.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!