String Pool behavior

前端 未结 6 1667
迷失自我
迷失自我 2021-01-18 02:55

I read this Questions about Java's String pool and understand the basic concept of string pool but still don\'t understand the behavior.

First: it works if you

6条回答
  •  轮回少年
    2021-01-18 03:39

    See the documentation for String#intern(). The last line there states:

    All literal strings and string-valued constant expressions are interned.

    Your += example is neither a literal string nor a string-valued constant expression, so it is not put in the String pool.

提交回复
热议问题