public int hashCode() {
int h = hash;
if (h == 0) {
int off = offset;
char val[] = value;//字符数组表示字符串
int len = count;//字符串字符个数 for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
hash = h;
}
return h;
}求解:
这个是string类内部的源代码,当字符串无限长的时候,这个for循环计算得到hashCode不会越界么?
int h = hash;
if (h == 0) {
int off = offset;
char val[] = value;//字符数组表示字符串
int len = count;//字符串字符个数 for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
hash = h;
}
return h;
}求解:
这个是string类内部的源代码,当字符串无限长的时候,这个for循环计算得到hashCode不会越界么?
那个是外部的count决定的,也就是hashCode这个方法在进行hash值比较的时候,长度是可以变化的。