— Scott McNealy, Sun Microsystems Chairman, President and ceo


takeThing(ArrayList list)



Download 40,57 Mb.
Pdf ko'rish
bet503/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   499   500   501   502   503   504   505   506   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

takeThing(ArrayList list)?
Here’s where it gets weird...
This:
public 

 void takeThing(ArrayList

 list)
 
Is NOT the same as this:
public void takeThing(ArrayList

 list)
 
Both are legal, but they’re different!
The first one, where  is part of the method 
declaration, means that any ArrayList declared of a type that is 
Animal, or one of Animal’s subtypes (like Dog or Cat), is legal. 
So you could invoke the top method using an ArrayList
ArrayList, or ArrayList.
But... the one on the bottom, where the method argument is 
(ArrayList list) means that only an ArrayList 
is legal. In other words, while the first version takes an ArrayList 
of any type that is a type of Animal (Animal, Dog, Cat, etc.), 
the second version takes only an ArrayList of type Animal. Not 
ArrayList, or ArrayList but only ArrayList.
And yes, it does appear to violate the point of polymorphism. 
but it will become clear when we revisit this in detail at the end 
of the chapter. For now, remember that we’re only looking at 
this because we’re still trying to figure out how to sort() that 
SongList, and that led us into looking at the API for the sort() 
method, which had this strange generic type declaration.
For now, all you need to know is that the syntax of the top version 
is legal, and that it means you can pass in a ArrayList object 
instantiated as Animal or any Animal subtype.
And now back to our sort() method...


546
 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   499   500   501   502   503   504   505   506   ...   555




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