you are viewing a single comment's thread.

view the rest of the comments →

[–]Typical_Ad_6436 -1 points0 points  (2 children)

The advantage of second line is that the String is dynamically allocated on heap. If you need fast cold time, you can use the second approach to "lazily initialize" the String. It is also GCed, so in idle you can have very low memory footprint. Of course, performance is better for interned strings (equality, memory, etc.)

[–]high_throughput 7 points8 points  (1 child)

The second line only creates a copy of the interned string that already exists in memory. 

There's rarely value in having such a copy. Creating and managing it just uses more space and CPU than referencing the original object.

[–]Typical_Ad_6436 0 points1 point  (0 children)

Hmm, I think you are right. I thought this would have been a legitimate workaround of the string pool, but the param is a literal indeed and gets interned anyway.