— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

%javac Jukebox3.java
Jukebox3.java:15: cannot find symbol
symbol : method sort(java.util.ArrayList)
location: class java.util.Collections
Collections.sort(songList);
^
1 error
And of course you probably already asked yourself, “What would it 
be sorting on?” How would the sort method even know what made 
one Song greater or less than another Song? Obviously if you want 
the song’s title to be the value that determines how the songs are 
sorted, you’ll need some way to tell the sort method that it needs 
to use the title and not, say, the beats per minute.
We’ll get into all that a few pages from now, but first, let’s find out 
why the compiler won’t even let us pass a Song ArrayList to the 
sort() method.
Collections.
sort()


collections 
with 
generics
you are here
4
539
The sort() method declaration
From the API docs (looking up the java.util.Collections class, and scrolling to the sort() 
method), it looks like the sort() method is declared... strangely. Or at least different from 
anything we’ve seen so far.
That’s because the sort() method (along with other things in the whole collection framework in 
Java) makes heavy use of generics. Anytime you see something with angle brackets in Java source 
code or documentation, it means generics—a feature added to Java 5.0. So it looks like we’ll 
have to learn how to interpret the documentation before we can fi gure out why we were able to 
sort String objects in an ArrayList, but not an ArrayList of Song objects.
WTF? I have no idea how to 
read the method declaration 
on this. It says that sort() 
takes a List, but what is 
T? And what is that big thing 
before the return type?



Download 40,57 Mb.

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