Effective Java



Download 2,19 Mb.
Pdf ko'rish
bet172/341
Sana11.07.2022
Hajmi2,19 Mb.
#776765
1   ...   168   169   170   171   172   173   174   175   ...   341
Bog'liq
Effective Java



ITEM 40: CONSISTENTLY USE THE OVERRIDE ANNOTATION
189
equals
method is not of type 
Object
, so 
Bigram
inherits the 
equals
method from
Object
. This 
equals
method tests for object 
identity
, just like the 
==
operator.
Each of the ten copies of each bigram is distinct from the other nine, so they are
deemed unequal by 
Object.equals
, which explains why the program prints 
260
.
Luckily, the compiler can help you find this error, but only if you help it by
telling it that you intend to override 
Object.equals
. To do this, annotate
Bigram.equals
with 
@Override
, as shown here:
@Override public boolean equals(Bigram b) {
return b.first == first && b.second == second;
}
If you insert this annotation and try to recompile the program, the compiler
will generate an error message like this:
Bigram.java:10: method does not override or implement a method 
from a supertype
@Override public boolean equals(Bigram b) {
^
You will immediately realize what you did wrong, slap yourself on the forehead,
and replace the broken 
equals
implementation with a correct one (Item 10):
@Override public boolean equals(

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   168   169   170   171   172   173   174   175   ...   341




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish