我不知道这是否会帮助任何人,但这似乎有效:
if(type == type_BooleanArray) {
boolean eq = Arrays.equals((boolean[]) thisObj, (boolean[]) thatObj);
if(!eq) {
return false;
}
} else if(type == type_ByteArray) {
boolean eq = Arrays.equals((byte[]) thisObj, (byte[]) thatObj);
if(!eq) {
return false;
}
} else if(type == type_ShortArray) {
boolean eq = Arrays.equals((short[]) thisObj, (short[]) thatObj);
if(!eq) {
return false;
}
} else if(type == type_CharArray) {
boolean eq = Arrays.equals((char[]) thisObj, (char[]) thatObj);
if(!eq) {
return false;
}
} else if(type == type_IntArray) {
boolean eq = Arrays.equals((int[]) thisObj, (int[]) thatObj);
if(!eq) {
return false;
}
} else if(type == type_LongArray) {
boolean eq = Arrays.equals((long[]) thisObj, (long[]) thatObj);
if(!eq) {
return false;
}
} else if(type == type_FloatArray) {
boolean eq = Arrays.equals((float[]) thisObj, (float[]) thatObj);
if(!eq) {
return false;
}
} else if(type == type_DoubleArray) {
boolean eq = Arrays.equals((double[]) thisObj, (double[]) thatObj);
if(!eq) {
return false;
}
} else {
if(!thisObj.equals(thatObj)) {
return false;
}
}
显然array.equals(otherArray)
做了 a array == otherArray
,而不是你所期望的。