What are the benefits of using identical String literals instead of a final variable?

前端 未结 6 1564
迷失自我
迷失自我 2020-12-08 19:25

I\'ve come across a class that includes multiple uses of a string literal, \"foo\".

What I\'d like to know, is what are the benefits and impact (in terms of object c

6条回答
  •  失恋的感觉
    2020-12-08 20:10

    Those string literals are internalized, so no new String objects are created in the loop. Using the same literal twice could still be a sign for code smell, though; but not in terms of speed or memory usage.

提交回复
热议问题