SORU
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ş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • AllYourNewsByMe

    AllYourNewsB

    18 Temmuz 2011
  • Edge-CGI 3D Tutorials and more!

    Edge-CGI 3D

    11 HAZİRAN 2013
  • RogerBuckChrist

    RogerBuckChr

    9 Temmuz 2011