— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

544
 
chapter 16
Using generic METHODS
A generic class means that the class declaration includes a type 
parameter. A generic method means that the method declaration 
uses a type parameter in its signature. 
You can use type parameters in a method in several different ways:
1
Using a type parameter defined in the class declaration
When you declare a type parameter for the class, you 
can simply use that type any place that you’d use a 
real class or interface type. The type declared in the 
method argument is essentially replaced with the type 
you use when you instantiate the class.
2
Using a type parameter that was NOT defined in the class declaration
If the class itself doesn’t use a type parameter, you can still 
specify one for a method, by declaring it in a really unusual 
(but available) space—before the return type. This method says 
that T can be “any type of Animal”.
public boolean add(
E
 o)
public class ArrayList

 extends AbstractList

 ... {

You can use the “E” here ONLY because it’s 


already been defined as part of the class.
public 

 void takeThing(ArrayList

 list)
 
Here we can use because we declared 
“T” earlier in the method declaration.
generic 
methods


collections 
with 
generics
you are here
4
545
Wait... that can’t be right. If you can 
take a list of Animal, why don’t you 
just SAY that? What’s wrong with just 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   498   499   500   501   502   503   504   505   ...   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