可能重复:
What is the purpose of the expression “new String(…)” in Java?为什么String类有复制构造函数?
如果一成不变的类的对象副本将等于原稿那么为什么在String
类在Java中有一个拷贝构造函数?这是一个错误还是这个实现背后有一个原因? 在Java文档中,规定:
/**
* Initializes a newly created {@code String} object so that it represents
* the same sequence of characters as the argument; in other words, the
* newly created string is a copy of the argument string. Unless an
* explicit copy of {@code original} is needed, use of this constructor is
* unnecessary since Strings are immutable.
*
* @param original
* A {@code String}
*/
public String(String original) {
....
....}
这不是“过于本地化”,这是一个很好的问题,适用于稍后发现它的人,提供非常有用的信息答案。 –
请参阅[本](http://stackoverflow.com/a/465682/1037210)回答。 – Lion
请注意,所提到的类似问题的答案现在可能已被部分废弃。 –