Effective Java



Download 2,19 Mb.
Pdf ko'rish
bet184/341
Sana11.07.2022
Hajmi2,19 Mb.
#776765
1   ...   180   181   182   183   184   185   186   187   ...   341
Bog'liq
Effective Java



CHAPTER 7
LAMBDAS AND STREAMS
202
are several reasons that 
Comparator
deserves its own interface. First, its name
provides excellent documentation every time it is used in an API, and it’s used a
lot. Second, the 
Comparator
interface has strong requirements on what constitutes
a valid instance, which comprise its 
general contract
. By implementing the
interface, you are pledging to adhere to its contract. Third, the interface is heavily
outfitted with useful default methods to transform and combine comparators.
You should seriously consider writing a purpose-built functional interface in
preference to using a standard one if you need a functional interface that shares
one or more of the following characteristics with 
Comparator
:
• It will be commonly used and could benefit from a descriptive name.
• It has a strong contract associated with it.
• It would benefit from custom default methods.
If you elect to write your own functional interface, remember that it’s an interface
and hence should be designed with great care (Item 21).
Notice that the 
EldestEntryRemovalFunction
interface (page 199) is labeled
with the 
@FunctionalInterface
annotation. This annotation type is similar in
spirit to 
@Override
. It is a statement of programmer intent that serves three
purposes: it tells readers of the class and its documentation that the interface was
designed to enable lambdas; it keeps you honest because the interface won’t com-
pile unless it has exactly one abstract method; and it prevents maintainers from
accidentally adding abstract methods to the interface as it evolves. 

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   180   181   182   183   184   185   186   187   ...   341




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