Effective Java



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



CHAPTER 7
LAMBDAS AND STREAMS
200
If one of the standard functional interfaces does the job, you should generally
use it in preference to a purpose-built functional interface.
This will make
your API easier to learn, by reducing its conceptual surface area, and will provide
significant interoperability benefits, as many of the standard functional interfaces
provide useful default methods. The 
Predicate
interface, for instance, provides
methods to combine predicates. In the case of our 
LinkedHashMap
example, the
standard 
BiPredicate,
Map.Entry>
interface should be used in
preference to a custom 
EldestEntryRemovalFunction
interface.
There are forty-three interfaces in 
java.util.Function
. You can’t be
expected to remember them all, but if you remember six basic interfaces, you can
derive the rest when you need them. The basic interfaces operate on object
reference types. The 
Operator
interfaces represent functions whose result and
argument types are the same. The 
Predicate
interface represents a function that
takes an argument and returns a 
boolean
. The 
Function
interface represents a
function whose argument and return types differ. The 
Supplier
interface
represents a function that takes no arguments and returns (or “supplies”) a value.
Finally, 
Consumer
represents a function that takes an argument and returns
nothing, essentially consuming its argument. The six basic functional interfaces
are summarized below:
There are also three variants of each of the six basic interfaces to operate on the
primitive types 
int

long
, and 
double
. Their names are derived from the basic
interfaces by prefixing them with a primitive type. So, for example, a predicate that
takes an 
int
is an 
IntPredicate
, and a binary operator that takes two 
long
values
and returns a 
long
is a 
LongBinaryOperator
. None of these variant types is
parameterized except for the 
Function
variants, which are parameterized by return
type. For example, 
LongFunction
takes a 
long
and returns an 
int[]
.

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   178   179   180   181   182   183   184   185   ...   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