在java String
source code中,有几个地方注意到以下注释:
// Note: offset or count might be near -1>>>1.
请考虑以下示例:
public String(char value[], int offset, int count) {
if (offset < 0) {
throw new StringIndexOutOfBoundsException(offset);
}
if (count < 0) {
throw new StringIndexOutOfBoundsException(count);
}
// Note: offset or count might be near -1>>>1.
if (offset > value.length - count) {
throw new StringIndexOutOfBoundsException(offset + count);
}
this.offset = 0;
this.count = count;
this.value = Arrays.copyOfRange(value, offset, offset+count);
}
我们可以看到,offset,value.length和count都是int,因此该值可能是-1,0,1或任何其他整数。什么是“近”和“>>>”在评论意味着,我在这里遗漏了什么?