Ada*_*ski 15

从API文档:

Unless an explicit copy of original is needed, use of this constructor is
unnecessary since Strings are immutable. 
Run Code Online (Sandbox Code Playgroud)

我能想到的唯一原因是:

  1. 你创造了一个非常大的String:A.
  2. 你已经创建了一个小的子字符串:B基于A.如果你看看你的实现,substring你会看到它引用原始字符串相同的char []数组.
  3. StringA已超出范围,您希望减少内存消耗.
  4. 创建B的显式副本意味着副本:B'不再引用大型char[].允许B超出范围将允许垃圾收集器回收返回char[]A和B 的大型,仅留下小的char[]后备B'.