— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet532/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   528   529   530   531   532   533   534   535   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

generic 
wildcards


collections 
with 
generics
you are here
4
575
Alternate syntax for doing the same thing
You probably remember that when we looked at the sort() method, 
it used a generic type, but with an unusual format where the type 
parameter was declared before the return type. It’s just a different way 
of declaring the type parameter, but the results are the same:
public 

 void takeThing(ArrayList

 list)
 
This:
public void takeThing(ArrayList

 list)
 
Does the same thing as this:
there are no
Dumb Questions
Q: 
If they both do the same thing, why would you use 
one over the other?
A: 
It all depends on whether you want to use “T” some-
where else. For example, what if you want the method to 
have two arguments—both of which are lists of a type that 
extend Animal? In that case, it’s more efficient to just declare 
the type parameter once:
Instead of typing:
public 

 void takeThing(ArrayList

 one, ArrayList

 two)
public void takeThing(ArrayList

 one,
ArrayList

 two)
 



576
 
chapter 16
Exercise
Your job is to play compiler and determine which of 
these statements would compile. But some of this 
code wasn’t covered in the chapter, so you need to 
work out the answers based on what you DID learn, 
applying the “rules” to these new situations. In 
some cases, you might have to guess, but the 
point is to come up with a reasonable answer 
based on what you know so far.
(Note: assume that this code is within a legal class and 
method.)

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   528   529   530   531   532   533   534   535   ...   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