Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Simon
Ri4er
Head
of
Java
Technology
Evangelism
Oracle
Corp
Twi4er:
@speakjava
Fork/Join
Framework
java.util.concurrent
(jsr166y)
(jsr166)
Phasers,
etc
java.lang.Thread
(jsr166)
1.0 5.0 6
1996 … 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014
7 8
Copyright
©
2014,
Oracle
and/or
its
affiliates.
All
rights
reserved.
Lambdas
In
Java
• More
readable
• More
abstract
• Less
error-‐prone
How
Copyright
©
2014,
Oracle
and/or
its
affiliates.
All
rights
reserved.
Lambda
Expression
Types
• Single-‐method
interfaces
are
used
extensively
in
Java
– DefiniRon:
a
func2onal
interface
is
an
interface
with
one
abstract
method
– Func2onal
interfaces
are
idenRfied
structurally
– The
type
of
a
lambda
expression
will
be
a
func2onal
interface
• Lambda
expressions
provide
implementaRons
of
the
abstract
method
• Lambda
expressions
can
refer
to
effec2vely
final
local
variables
from
the
enclosing
scope
• EffecRvely
final:
A
variable
that
meets
the
requirements
for
final
variables
(i.e.,
assigned
once),
even
if
not
explicitly
declared
final
• Closures
on
values,
not
variables
FileFilter x = File::canRead;
Replace with
Factory<List<String>> f = ArrayList<String>::new;
• The
pipeline
is
only
evaluated
when
the
terminal
operaRon
is
called
– All
operaRons
can
execute
sequenRally
or
in
parallel
– Intermediate
operaRons
can
be
merged
• Avoiding
mulRple
redundant
passes
on
data
• Short-‐circuit
operaRons
(e.g.
findFirst)
• Lazy
evaluaRon
– Stream
characterisRcs
help
idenRfy
opRmisaRons
• DISTINT
stream
passed
to
distinct()
is
a
no-‐op
1-‐to-‐1
mapping
Input
Stream
Output
Stream
Map
1-‐to-‐many
mapping
Input
Stream
Output
Stream
FlatMap