次はのStringクラス'originalValue.length> size'はStringコンストラクタでどのように起こりますか?
public String(String original) {
int size = original.count;
char[] originalValue = original.value;
char[] v;
if (originalValue.length > size) {
// The array representing the String is bigger than the new
// String itself. Perhaps this constructor is being called
// in order to trim the baggage, so make a copy of the array.
int off = original.offset;
v = Arrays.copyOfRange(originalValue, off, off+size);
} else {
// The array representing the String is the same
// size as the String, so no point in making a copy.
v = originalValue;
}
this.offset = 0;
this.count = size;
this.value = v;
}
のコンストラクタです。しかし、私は
if (originalValue.length > size)
が起こる可能性がどのようだろうか?コメントは、手荷物をくすぐる、何ですか手荷物を参照してください?
このStringクラスの他のコンストラクタとメソッドを見てください。実際のコンテンツに必要なものよりも、配列内に割り当てられた領域が大きい文字列を作成する方法はありますか? –