Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is getting me confused

 
vinayak manda
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
vinayak manda
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'am sorry, I couldn't post the question before...

The question is when String s3 gets the value "EFG" and later s4 also gets the value "EFG", as the literal goes into the string pool,then s3 and s4 should point to the same reference.
Then why should (s3 == s4) return false.

Please clear this doubt.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
s3 gets a reference to a new String("EFG") and s4 gets a reference to another new String("EFG"). So s3 and s4 refer to different objects. Therefore s3 == s4 results in false.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only String literals go into the pool by default. You can use the intern() method for the others to enforce them to get into the pool, too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic