Poniżej konstruktor String klasyJak może się zdarzyć "originalValue.length> size" w konstruktorze 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;
}
Ale zastanawiam się, jak
if (originalValue.length > size)
może się zdarzyć? Komentarz mówi: "przyciąć bagaż", do czego odnosi się bagaż?
Zobacz inne konstruktory i metody tej klasy String. Czy istnieje sposób na utworzenie łańcucha z większą przydzieloną przestrzenią w tablicy niż to, co jest potrzebne dla rzeczywistej zawartości? –