Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confusion with strings

 
Kitty Dayal
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



Code compiles fine, but does not print anything.

Am right with my understanding and what am i missing here?

Thanks a lot.
Kits
 
Tybon Wu
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are the correct comments for the code:

 
Kitty Dayal
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tybon Wu:

Thanks for reply. But my question was related to duplication of objects in the pool. Since there is already a "abc" present, Will it not use it? Or Why does it not use it here?

Since this is true
[/QB]
 
Tybon Wu
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kitty Dayal:
Thanks for reply. But my question was related to duplication of objects in the pool. Since there is already a "abc" present, Will it not use it? Or Why does it not use it here?


The objects in the pool are used only in constant expressions or by calling the intern() method. Since x.concat("c") is calculated at runtime, objects in the pool are not used. Let me give you a few more examples:
 
Kitty Dayal
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tybon,

Thanks for the usefull information.
Kiran.
 
Mohit Agarwal
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to both of you , to kiran fort posting this doubt and to Tybon Wu
for clearing it out. Mr. Tybon Wu
can you throw some light on intern() method as i had heard about it for the first time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic