可能性の重複:
What is the purpose of the expression “new String(…)” in Java?Stringクラスにコピーコンストラクタがあるのはなぜですか?
不変クラスは、コピーがオリジナルに等しくなるオブジェクトの場合は、なぜJavaでString
クラスはコピーコンストラクタを持っているのですか?間違いか、この実装の背後に理由がありますか? 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) {
....
....}
これはあまりにもローカライズされているわけではありません。後で見つけた方には、非常に有益な回答があります。 –
[this](http://stackoverflow.com/a/465682/1037210)の回答を参照してください。 – Lion
前述の類似の質問に対する回答は、おそらく部分的に廃止されたと考えられる可能性があることに注意してください。 –