这是 Java 中 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)这行代码是我关心的,我不认为这个条件对于 IF 内部正在执行的所有代码都是正确的。String 实际上是一个字符数组。original.count应该等于它的值的长度(它的值是一个字符数组),所以这种情况不会发生。
我可能是错的,所以我需要你的解释。谢谢你的帮助。
维哈隆。