存储在字符串池中的字符串文字是否唯一?
我知道字符串可能会被保留,但它是创建新字符串对象时认真执行的操作吗?
Jls 第 3.10.5 节字符串文字。
I understand that Strings may be interned, but it it an action that is performed religiously when a new string object is created?
Jls section 3.10.5 string literals.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所有
String
文字都进入字符串池。否则,您的应用程序必须对String
调用intern()
,否则它不会进入池中。String
文字是出现在源代码中的带有双引号的字符串:在此示例中,
"Hello, "
是文字字符串。它在实习生池中。它也由变量greeting
引用。s
引用的String
不是文字,也不在实习池中……除非您进行此调用:All
String
literals go into the string pool. Otherwise, your application must callintern()
on theString
, or it won't go into the pool.A
String
literal is a string that appears in source code with double quotes around it:In this example,
"Hello, "
is a literal string. It is in the intern pool. It is also referenced by the variablegreeting
.The
String
referred to bys
is not a literal, and is not in the intern pool… unless you make this call: