28 NİSAN 2010, ÇARŞAMBA
() Java Tamsayı compareTo - neden çıkarma vs karşılaştırma kullan?
compareTo
yöntem java.lang.Integer
uygulama aşağıdaki gibi görünüyor fark ettik
public int compareTo(Integer anotherInteger) {
int thisVal = this.value;
int anotherVal = anotherInteger.value;
return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
}
Soru çıkarma yerine karşılaştırması kullanmak nedeni budur:
return thisVal - anotherVal;
CEVAP
28 NİSAN 2010, ÇARŞAMBA
Bu tamsayı taşması nedeniyle. thisVal
çok büyük ve anotherVal
negatif olduğunda o zaman eski ikinci çıkararak negatif dizi taşması olabilir thisVal
daha büyük bir sonuç verir.
Bunu Paylaş:
Neden Java'In hashCode() Dize çar...
Neden int-Nesne bir karşılaştırma geçe...
Neden java Dize Tamsayı döküm olamaz?...
Neden bir Numaralama Java son compareT...
Neden char[] şifreler için Dize Java t...