— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet499/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   495   496   497   498   499   500   501   502   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

generic 
types


collections 
with 
generics
you are here
4
541
1
Creating instances of generified 
classes (like ArrayList)
When you make an ArrayList, you have to tell it the type 
of objects you’ll allow in the list, just as you do with plain 
old arrays.
3
Declaring (and invoking) 
methods that take generic types
If you have a method that takes as a parameter, say, an 
ArrayList of Animal objects, what does that really mean? 
Can you also pass it an ArrayList of Dog objects? We’ll 
look at some subtle and tricky polymorphism issues that 
are very different from the way you write methods that 
take plain old arrays.
(This is actually the same point as #2, but that shows you 
how important we think it is.)
2
Declaring and assigning 
variables of generic types
How does polymorphism really work with generic 
types? If you have an ArrayList reference 
variable, can you assign an ArrayList to it? What 
about a List reference? Can you assign an 
ArrayList to it? You’ll see...
Learning generics
Of the dozens of things you could learn about generics, there are 
really only three that matter to most programmers:
new ArrayList
()
List
 
songList = 
new ArrayList
()
void foo(List
 
list)
x.foo(songList)
Q: 
But don’t I also need to learn how to create my OWN generic 
classes? What if I want to make a class type that lets people 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   495   496   497   498   499   500   501   502   ...   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