Nie wiem, czy to pomoże nikomu, ale to wydaje się działać:
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;
}
}
Widocznie array.equals(otherArray)
robi array == otherArray
, a nie to, czego się spodziewać .
Zostałem skulony! –
Pomyślałem, że istnieje metoda biblioteczna, ale tweakt wyrzucił mnie, wspominając deepEquals() tuż przy kiju. Arrays.equals() robi dokładnie to samo, co ta metoda z twoją zmianą, chociaż przechowuje również długość w zmiennej tymczasowej (przed porównywaniem długości). –
Dzięki! I wiedziałem o tym trochę, dzięki za przypomnienie mi ... człowiek SO sprawił, że jestem leniwy! –