Are strings created with + concatenation stored in the string pool?

前端 未结 6 730
盖世英雄少女心
盖世英雄少女心 2020-12-09 06:16

For instance

 String s = \"Hello\" + \" World\";

I know there are two strings in the pool \"Hello\" and \"World\" but, does: \"Hello World\

6条回答
  •  长情又很酷
    2020-12-09 06:39

    No. Only string literals are required to go into the pool. Compilers may optimize away the concatenation and may store additional string literals in the pool.

提交回复
热议问题