SlideShare a Scribd company logo
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas 
& 
Streams 
In 
JDK8 
Making 
Bulk 
Opera/ons 
Simple 
Simon 
Ri6er 
Head 
of 
Java 
Technology 
Evangelism 
Oracle 
Corp. 
Twi6er: 
@speakjava 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Safe 
Harbor 
Statement 
The 
following 
is 
intended 
to 
outline 
our 
general 
product 
direcTon. 
It 
is 
intended 
for 
informaTon 
purposes 
only, 
and 
may 
not 
be 
incorporated 
into 
any 
contract. 
It 
is 
not 
a 
commitment 
to 
deliver 
any 
material, 
code, 
or 
funcTonality, 
and 
should 
not 
be 
relied 
upon 
in 
making 
purchasing 
decisions. 
The 
development, 
release, 
and 
Tming 
of 
any 
features 
or 
funcTonality 
described 
for 
Oracle’s 
products 
remains 
at 
the 
sole 
discreTon 
of 
Oracle. 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
3
java.util.concurrent 
(jsr166) 
1.0 5.0 6 7 8 
1996 … 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
java.lang.Thread 
Fork/Join 
Framework 
(jsr166y) 
Concurrency 
in 
Java 
Project 
Lambda 
Phasers, 
etc 
(jsr166)
Lambdas 
In 
Java 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
The 
Problem: 
External 
IteraTon 
List<Student> 
students 
= 
... 
double 
highestScore 
= 
0.0; 
for 
(Student 
s 
: 
students) 
{ 
if 
(s.getGradYear() 
== 
2011) 
{ 
if 
(s.getScore() 
> 
highestScore) 
highestScore 
= 
s.score; 
} 
} 
• Our 
code 
controls 
iteraTon 
• Inherently 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
serial: 
iterate 
from 
beginning 
to 
end 
• Not 
thread-­‐safe 
• Business 
logic 
is 
stateful 
• Mutable 
accumulator 
variable
Internal 
IteraTon 
With 
Inner 
Classes 
• IteraTon 
handled 
by 
the 
library 
• Not 
inherently 
serial 
– 
traversal 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
may 
be 
done 
in 
parallel 
• Traversal 
may 
be 
done 
lazily 
– 
so 
one 
pass, 
rather 
than 
three 
• Thread 
safe 
– 
client 
logic 
is 
stateless 
• High 
barrier 
to 
use 
– SyntacTcally 
ugly 
More 
FuncTonal 
double 
highestScore 
= 
students 
.filter(new 
Predicate<Student>() 
{ 
public 
boolean 
op(Student 
s) 
{ 
return 
s.getGradYear() 
== 
2011; 
} 
}) 
.map(new 
Mapper<Student,Double>() 
{ 
public 
Double 
extract(Student 
s) 
{ 
return 
s.getScore(); 
} 
}) 
.max();
Internal 
IteraTon 
With 
Lambdas 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
List<Student> 
students 
= 
... 
double 
highestScore 
= 
students 
.filter(Student 
s 
-­‐> 
s.getGradYear() 
== 
2011) 
.map(Student 
s 
-­‐> 
s.getScore()) 
.max(); 
• More 
readable 
• More 
abstract 
• Less 
error-­‐prone 
NOTE: 
This 
is 
not 
JDK8 
code
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Lambda 
Expressions 
Some 
Details 
• Lambda 
expressions 
represent 
anonymous 
funcTons 
– Same 
structure 
as 
a 
method 
• typed 
argument 
list, 
return 
type, 
set 
of 
thrown 
excepTons, 
and 
a 
body 
– Not 
associated 
with 
a 
class 
• We 
now 
have 
parameterised 
behaviour, 
not 
just 
values 
double 
highestScore 
= 
students. 
filter(Student 
s 
-­‐> 
s.getGradYear() 
== 
2011). 
map(Student 
s 
-­‐> 
s.getScore()) 
max(); 
What 
How
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Lambda 
Expression 
Types 
• Single-­‐method 
interfaces 
are 
used 
extensively 
in 
Java 
– DefiniTon: 
a 
func2onal 
interface 
is 
an 
interface 
with 
one 
abstract 
method 
– Func2onal 
interfaces 
are 
idenTfied 
structurally 
– The 
type 
of 
a 
lambda 
expression 
will 
be 
a 
func2onal 
interface 
• Lambda 
expressions 
provide 
implementaTons 
of 
the 
abstract 
method 
interface 
Comparator<T> 
{ 
boolean 
compare(T 
x, 
T 
y); 
} 
interface 
FileFilter 
{ 
boolean 
accept(File 
x); 
} 
interface 
Runnable 
{ 
void 
run(); 
} 
interface 
ActionListener 
{ 
void 
actionPerformed(…); 
} 
interface 
Callable<T> 
{ 
T 
call(); 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Local 
Variable 
Capture 
• Lambda 
expressions 
can 
refer 
to 
effec2vely 
final 
local 
variables 
from 
the 
enclosing 
scope 
• EffecTvely 
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 
void 
expire(File 
root, 
long 
before) 
{ 
root.listFiles(File 
p 
-­‐> 
p.lastModified() 
<= 
before); 
}
What 
Does 
‘this’ 
Mean 
For 
Lambdas? 
• ‘this’ 
refers 
to 
the 
enclosing 
object, 
not 
the 
lambda 
itself 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Think 
of 
‘this’ 
as 
a 
final 
predefined 
local 
• Remember 
the 
Lambda 
is 
an 
anonymous 
func2on 
– It 
is 
not 
associated 
with 
a 
class 
– Therefore 
there 
can 
be 
no 
‘this’ 
for 
the 
Lambda
Referencing 
Instance 
Variables 
Which 
are 
not 
final, 
or 
effecTvely 
final 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
class 
DataProcessor 
{ 
private 
int 
currentValue; 
public 
void 
process() 
{ 
DataSet 
myData 
= 
myFactory.getDataSet(); 
dataSet.forEach(d 
-­‐> 
d.use(currentValue++)); 
} 
}
Referencing 
Instance 
Variables 
The 
compiler 
helps 
us 
out 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
class 
DataProcessor 
{ 
private 
int 
currentValue; 
public 
void 
process() 
{ 
DataSet 
myData 
= 
myFactory.getDataSet(); 
dataSet.forEach(d 
-­‐> 
d.use(this.currentValue++); 
} 
} 
‘this’ 
(which 
is 
effecTvely 
final) 
inserted 
by 
the 
compiler
static 
T 
void 
sort(List<T> 
l, 
Comparator<? 
super 
T> 
c); 
List<String> 
list 
= 
getList(); 
Collections.sort(list, 
(String 
x, 
String 
y) 
-­‐> 
x.length() 
-­‐ 
y.length()); 
Collections.sort(list, 
(x, 
y) 
-­‐> 
x.length() 
-­‐ 
y.length()); 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Type 
Inference 
• The 
compiler 
can 
oien 
infer 
parameter 
types 
in 
a 
lambda 
expression 
§ Inferrence 
based 
on 
the 
target 
funcTonal 
interface’s 
method 
signature 
• Fully 
staTcally 
typed 
(no 
dynamic 
typing 
sneaking 
in) 
– More 
typing 
with 
less 
typing
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Method 
References 
• Method 
references 
let 
us 
reuse 
a 
method 
as 
a 
lambda 
expression 
FileFilter 
x 
= 
File 
f 
-­‐> 
f.canRead(); 
FileFilter 
x 
= 
File::canRead;
Factory<List<String>> 
f 
= 
() 
-­‐> 
return 
new 
ArrayList<String>(); 
Replace 
with 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Constructor 
References 
• Same 
concept 
as 
a 
method 
reference 
– For 
the 
constructor 
Factory<List<String>> 
f 
= 
ArrayList<String>::new;
Library 
EvoluTon 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
int 
heaviestBlueBlock 
= 
blocks 
.filter(b 
-­‐> 
b.getColor() 
== 
BLUE) 
.map(Block::getWeight) 
.reduce(0, 
Integer::max); 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Library 
EvoluTon 
Goal 
• Requirement: 
aggregate 
operaTons 
on 
collecTons 
– New 
methods 
required 
on 
CollecTons 
to 
facilitate 
this 
• This 
is 
problemaTc 
– Can’t 
add 
new 
methods 
to 
interfaces 
without 
modifying 
all 
implementaTons 
– Can’t 
necessarily 
find 
or 
control 
all 
implementaTons
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
SoluTon: 
Default 
Methods 
• Specified 
in 
the 
interface 
• From 
the 
caller’s 
perspecTve, 
just 
an 
ordinary 
interface 
method 
• Provides 
a 
default 
implementaTon 
• Default 
only 
used 
when 
implementaTon 
classes 
do 
not 
provide 
a 
body 
for 
the 
extension 
method 
• ImplementaTon 
classes 
can 
provide 
a 
be6er 
version, 
or 
not 
interface 
Collection<E> 
{ 
default 
Stream<E> 
stream() 
{ 
return 
StreamSupport.stream(spliterator()); 
} 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Virtual 
Extension 
Methods 
Stop 
right 
there! 
• Err, 
isn’t 
this 
implemenTng 
mulTple 
inheritance 
for 
Java? 
• Yes, 
but 
Java 
already 
has 
mulTple 
inheritance 
of 
types 
• This 
adds 
mulTple 
inheritance 
of 
behavior 
too 
• But 
not 
state, 
which 
is 
where 
most 
of 
the 
trouble 
is 
• Can 
sTll 
be 
a 
source 
of 
complexity 
• Class 
implements 
two 
interfaces, 
both 
of 
which 
have 
default 
methods 
• Same 
signature 
• How 
does 
the 
compiler 
differenTate? 
• StaTc 
methods 
also 
allowed 
in 
interfaces 
in 
Java 
SE 
8
FuncTonal 
Interface 
DefiniTon 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Single 
Abstract 
Method 
(SAM) 
type 
• A 
funcTonal 
interface 
is 
an 
interface 
that 
has 
one 
abstract 
method 
– Represents 
a 
single 
funcTon 
contract 
– Doesn’t 
mean 
it 
only 
has 
one 
method 
• @FunctionalInterface 
annotaTon 
– Helps 
ensure 
the 
funcTonal 
interface 
contract 
is 
honoured 
– Compiler 
error 
if 
not 
a 
SAM
Lambdas 
In 
Full 
Flow: 
Streams 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Aggregate 
OperaTons 
• Most 
business 
logic 
is 
about 
aggregate 
operaTons 
– “Most 
profitable 
product 
by 
region” 
– “Group 
transacTons 
by 
currency” 
• As 
we 
have 
seen, 
up 
to 
now, 
Java 
uses 
external 
iteraTon 
– Inherently 
serial 
– FrustraTngly 
imperaTve 
• Java 
SE 
8’s 
answer: 
The 
Stream 
API 
– With 
help 
from 
Lambdas
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Stream 
Overview 
At 
The 
High 
Level 
• AbstracTon 
for 
specifying 
aggregate 
computaTons 
– Not 
a 
data 
structure 
– Can 
be 
infinite 
• Simplifies 
the 
descripTon 
of 
aggregate 
computaTons 
– Exposes 
opportuniTes 
for 
opTmisaTon 
– Fusing, 
laziness 
and 
parallelism
Source 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Stream 
Overview 
• A 
stream 
pipeline 
consists 
of 
three 
types 
of 
things 
– A 
source 
– Zero 
or 
more 
intermediate 
operaTons 
– A 
terminal 
operaTon 
• Producing 
a 
result 
or 
a 
side-­‐effect 
Pipeline 
int 
total 
= 
transactions.stream() 
.filter(t 
-­‐> 
t.getBuyer().getCity().equals(“London”)) 
.mapToInt(Transaction::getPrice) 
.sum(); 
Intermediate 
operaTon 
Terminal 
operaTon
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Stream 
Sources 
Many 
Ways 
To 
Create 
• From 
collecTons 
and 
arrays 
– Collection.stream() 
– Collection.parallelStream() 
– Arrays.stream(T 
array) 
or 
Stream.of() 
• StaTc 
factories 
– IntStream.range() 
– Files.walk() 
• Roll 
your 
own 
– java.util.Spliterator
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Stream 
Sources 
Provide 
• Access 
to 
stream 
elements 
• DecomposiTon 
(for 
parallel 
operaTons) 
– Fork-­‐join 
framework 
• Stream 
characterisTcs 
– ORDERED 
– SORTED 
– DISTINCT 
– SIZED 
– NONNULL 
– IMMUTABLE 
– CONCURRENT
Stream 
Terminal 
OperaTons 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• The 
pipeline 
is 
only 
evaluated 
when 
the 
terminal 
operaTon 
is 
called 
– All 
operaTons 
can 
execute 
sequenTally 
or 
in 
parallel 
– Intermediate 
operaTons 
can 
be 
merged 
• Avoiding 
mulTple 
redundant 
passes 
on 
data 
• Short-­‐circuit 
operaTons 
(e.g. 
findFirst) 
• Lazy 
evaluaTon 
– Stream 
characterisTcs 
help 
idenTfy 
opTmisaTons 
• DISTINT 
stream 
passed 
to 
distinct() 
is 
a 
no-­‐op
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Maps 
and 
FlatMaps 
Map 
Values 
in 
a 
Stream 
Map 
FlatMap 
Input 
Stream 
Input 
Stream 
1-­‐to-­‐1 
mapping 
1-­‐to-­‐many 
mapping 
Output 
Stream 
Output 
Stream
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Optional<T> 
Reducing 
NullPointerException 
Occurrences 
String 
direction 
= 
gpsData.getPosition().getLatitude().getDirection(); 
String 
direction 
= 
“UNKNOWN”; 
if 
(gpsData 
!= 
null) 
{ 
Position 
p 
= 
gpsData.getPosition(); 
if 
(p 
!= 
null) 
{ 
Latitude 
latitude 
= 
p.getLatitude(); 
if 
(latitude 
!= 
null) 
direction 
= 
latitude.getDirection(); 
} 
}
NullPointerException 
Occurrences 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Optional<T> 
Reducing 
• Indicates 
that 
reference 
may, 
or 
may 
not 
have 
a 
value 
– Makes 
developer 
responsible 
for 
checking 
– A 
bit 
like 
a 
stream 
that 
can 
only 
have 
zero 
or 
one 
elements 
Optional<GPSData> 
maybeGPS 
= 
Optional.ofNullable(gpsData); 
maybeGPS.ifPresent(GPSData::printPosition); 
GPSData 
gps 
= 
maybeGPS.orElse(new 
GPSData()); 
maybeGPS.filter(g 
-­‐> 
g.lastRead() 
< 
2).ifPresent(GPSData.display());
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Example 
1 
Convert 
words 
in 
list 
to 
upper 
case 
List<String> 
output 
= 
wordList 
.stream() 
.map(String::toUpperCase) 
.collect(Collectors.toList());
Example 
1 
Convert 
words 
in 
list 
to 
upper 
case 
(in 
parallel) 
List<String> 
output 
= 
wordList 
.parallelStream() 
.map(String::toUpperCase) 
.collect(Collectors.toList()); 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Example 
2 
• BufferedReader 
has 
new 
method 
– Stream<String> 
lines() 
Count 
lines 
in 
a 
file 
long 
count 
= 
bufferedReader 
.lines() 
.count();
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Example 
3 
Join 
lines 
3-­‐4 
into 
a 
single 
string 
String 
output 
= 
bufferedReader 
.lines() 
.skip(2) 
.limit(2) 
.collect(Collectors.joining());
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Example 
4 
Collect 
all 
words 
in 
a 
file 
into 
a 
list 
List<String> 
output 
= 
reader 
.lines() 
.flatMap(line 
-­‐> 
Stream.of(line.split(REGEXP))) 
.filter(word 
-­‐> 
word.length() 
> 
0) 
.collect(Collectors.toList());
Example 
5 
List 
of 
unique 
words 
in 
lowercase, 
sorted 
by 
length 
List<String> 
output 
= 
reader 
.lines() 
.flatMap(line 
-­‐> 
Stream.of(line.split(REGEXP))) 
.filter(word 
-­‐> 
word.length() 
> 
0) 
.map(String::toLowerCase) 
.distinct() 
.sorted((x, 
y) 
-­‐> 
x.length() 
-­‐ 
y.length()) 
.collect(Collectors.toList()); 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Example 
6: 
Real 
World 
Infinite 
stream 
from 
thermal 
sensor 
private 
int 
double 
currentTemperature; 
... 
thermalReader 
.lines() 
.mapToDouble(s 
-­‐> 
Double.parseDouble(s.substring(0, 
s.length() 
-­‐ 
1))) 
.map(t 
-­‐> 
((t 
– 
32) 
* 
5 
/ 
9) 
.filter(t 
-­‐> 
t 
!= 
currentTemperature) 
.peek(t 
-­‐> 
listener.ifPresent(l 
-­‐> 
l.temperatureChanged(t))) 
.forEach(t 
-­‐> 
currentTemperature 
= 
t); 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Example 
6: 
Real 
World 
Infinite 
stream 
from 
thermal 
sensor 
private 
int 
double 
currentTemperature; 
... 
thermalReader 
.lines() 
.mapToDouble(s 
-­‐> 
Double.parseDouble(s.substring(0, 
s.length() 
-­‐ 
))) 
.map(t 
-­‐> 
((t 
– 
32) 
* 
5 
/ 
9) 
.filter(t 
-­‐> 
t 
!= 
this.currentTemperature) 
.peek(t 
-­‐> 
listener.ifPresent(l 
-­‐> 
l.temperatureChanged(t))) 
.forEach(t 
-­‐> 
this.currentTemperature 
= 
t); 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Conclusions 
• Java 
needs 
lambda 
statements 
– Significant 
improvements 
in 
exisTng 
libraries 
are 
required 
• Require 
a 
mechanism 
for 
interface 
evoluTon 
– SoluTon: 
virtual 
extension 
methods 
• Bulk 
operaTons 
on 
CollecTons 
– Much 
simpler 
with 
Lambdas 
• Java 
SE 
8 
evolves 
the 
language, 
libraries, 
and 
VM 
together
Simon 
Ri6er 
Oracle 
CorporarTon 
Twi6er: 
@speakjava 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.

More Related Content

What's hot (20)

PDF
Java SE 8 library design
Stephen Colebourne
 
PDF
Apouc 2014-java-8-create-the-future
OUGTH Oracle User Group in Thailand
 
PPTX
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Emiel Paasschens
 
PPTX
Java 8 Features
Leninkumar Koppoju
 
PPTX
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
jaxLondonConference
 
PDF
Java SE 8 best practices
Stephen Colebourne
 
PPT
java programming - applets
HarshithaAllu
 
PDF
The Java Carputer
Simon Ritter
 
PPTX
java 8 new features
Rohit Verma
 
PPTX
Java 8 Features
Trung Nguyen
 
PDF
Java 8 Lambda Expressions & Streams
NewCircle Training
 
PDF
Functional Java 8 - Introduction
Łukasz Biały
 
PDF
Automatic Migration of Legacy Java Method Implementations to Interfaces
Raffi Khatchadourian
 
PPTX
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
DevelopIntelligence
 
PDF
Lambdas & Streams
C4Media
 
PPTX
Java 8 - Features Overview
Sergii Stets
 
PDF
Exception handling
Ravi Kant Sahu
 
PPTX
Lambda Expressions in Java 8
icarter09
 
PPTX
Functional programming with Java 8
LivePerson
 
PPTX
Java 8 new features
Aniket Thakur
 
Java SE 8 library design
Stephen Colebourne
 
Apouc 2014-java-8-create-the-future
OUGTH Oracle User Group in Thailand
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Emiel Paasschens
 
Java 8 Features
Leninkumar Koppoju
 
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
jaxLondonConference
 
Java SE 8 best practices
Stephen Colebourne
 
java programming - applets
HarshithaAllu
 
The Java Carputer
Simon Ritter
 
java 8 new features
Rohit Verma
 
Java 8 Features
Trung Nguyen
 
Java 8 Lambda Expressions & Streams
NewCircle Training
 
Functional Java 8 - Introduction
Łukasz Biały
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Raffi Khatchadourian
 
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
DevelopIntelligence
 
Lambdas & Streams
C4Media
 
Java 8 - Features Overview
Sergii Stets
 
Exception handling
Ravi Kant Sahu
 
Lambda Expressions in Java 8
icarter09
 
Functional programming with Java 8
LivePerson
 
Java 8 new features
Aniket Thakur
 

Similar to Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter (20)

PPTX
Lambdas and-streams-s ritter-v3
Simon Ritter
 
PPTX
What's New in Java 8
javafxpert
 
PDF
Java 8
vilniusjug
 
PDF
Project Lambda: To Multicore and Beyond
Dmitry Buzdin
 
PPTX
java8
Arik Abulafya
 
PDF
Java 8 by example!
Mark Harrison
 
PDF
Java8
Felipe Mamud
 
PPTX
The Road to Lambda - Mike Duigou
jaxconf
 
PPTX
Java gets a closure
Tomasz Kowalczewski
 
PPTX
Java SE 8
Murali Pachiyappan
 
PPTX
java150929145120-lva1-app6892 (2).pptx
BruceLee275640
 
PDF
Java 8 Workshop
Mario Fusco
 
PPTX
Java 8 presentation
Van Huong
 
PPTX
Java 8 lambda
Masudul Haque
 
PDF
Productive Programming in Java 8 - with Lambdas and Streams
Ganesh Samarthyam
 
PPTX
Java 8 Feature Preview
Jim Bethancourt
 
PPTX
Java 8 - An Overview
Indrajit Das
 
PDF
Java 8
Sheeban Singaram
 
PPTX
A brief tour of modern Java
Sina Madani
 
PDF
JSR 335 / java 8 - update reference
sandeepji_choudhary
 
Lambdas and-streams-s ritter-v3
Simon Ritter
 
What's New in Java 8
javafxpert
 
Java 8
vilniusjug
 
Project Lambda: To Multicore and Beyond
Dmitry Buzdin
 
Java 8 by example!
Mark Harrison
 
The Road to Lambda - Mike Duigou
jaxconf
 
Java gets a closure
Tomasz Kowalczewski
 
java150929145120-lva1-app6892 (2).pptx
BruceLee275640
 
Java 8 Workshop
Mario Fusco
 
Java 8 presentation
Van Huong
 
Java 8 lambda
Masudul Haque
 
Productive Programming in Java 8 - with Lambdas and Streams
Ganesh Samarthyam
 
Java 8 Feature Preview
Jim Bethancourt
 
Java 8 - An Overview
Indrajit Das
 
A brief tour of modern Java
Sina Madani
 
JSR 335 / java 8 - update reference
sandeepji_choudhary
 
Ad

More from JAXLondon2014 (20)

PDF
GridGain 6.0: Open Source In-Memory Computing Platform - Nikita Ivanov
JAXLondon2014
 
PDF
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
JAXLondon2014
 
PPTX
How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...
JAXLondon2014
 
PDF
Conditional Logging Considered Harmful - Sean Reilly
JAXLondon2014
 
PDF
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
JAXLondon2014
 
PPT
API Management - a hands on workshop - Paul Fremantle
JAXLondon2014
 
PDF
'Bootiful' Code with Spring Boot - Josh Long
JAXLondon2014
 
PDF
The Full Stack Java Developer - Josh Long
JAXLondon2014
 
PDF
The Economies of Scaling Software - Josh Long and Abdelmonaim Remani
JAXLondon2014
 
PDF
Dataflow, the Forgotten Way - Russel Winder
JAXLondon2014
 
PDF
Habits of Highly Effective Technical Teams - Martijn Verburg
JAXLondon2014
 
PDF
The Lazy Developer's Guide to Cloud Foundry - Holly Cummins
JAXLondon2014
 
PPTX
Testing within an Agile Environment - Beyza Sakir and Chris Gollop
JAXLondon2014
 
PDF
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
JAXLondon2014
 
PDF
Squeezing Performance of out of In-Memory Data Grids - Fuad Malikov
JAXLondon2014
 
PDF
Spocktacular Testing - Russel Winder
JAXLondon2014
 
PDF
Server Side JavaScript on the Java Platform - David Delabassee
JAXLondon2014
 
PDF
Reflection Madness - Dr. Heinz Kabutz
JAXLondon2014
 
PDF
Rapid Web Application Development with MongoDB and the JVM - Trisha Gee
JAXLondon2014
 
PDF
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
JAXLondon2014
 
GridGain 6.0: Open Source In-Memory Computing Platform - Nikita Ivanov
JAXLondon2014
 
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
JAXLondon2014
 
How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...
JAXLondon2014
 
Conditional Logging Considered Harmful - Sean Reilly
JAXLondon2014
 
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
JAXLondon2014
 
API Management - a hands on workshop - Paul Fremantle
JAXLondon2014
 
'Bootiful' Code with Spring Boot - Josh Long
JAXLondon2014
 
The Full Stack Java Developer - Josh Long
JAXLondon2014
 
The Economies of Scaling Software - Josh Long and Abdelmonaim Remani
JAXLondon2014
 
Dataflow, the Forgotten Way - Russel Winder
JAXLondon2014
 
Habits of Highly Effective Technical Teams - Martijn Verburg
JAXLondon2014
 
The Lazy Developer's Guide to Cloud Foundry - Holly Cummins
JAXLondon2014
 
Testing within an Agile Environment - Beyza Sakir and Chris Gollop
JAXLondon2014
 
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
JAXLondon2014
 
Squeezing Performance of out of In-Memory Data Grids - Fuad Malikov
JAXLondon2014
 
Spocktacular Testing - Russel Winder
JAXLondon2014
 
Server Side JavaScript on the Java Platform - David Delabassee
JAXLondon2014
 
Reflection Madness - Dr. Heinz Kabutz
JAXLondon2014
 
Rapid Web Application Development with MongoDB and the JVM - Trisha Gee
JAXLondon2014
 
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
JAXLondon2014
 
Ad

Recently uploaded (17)

PPTX
Great-Books. Powerpoint presentation. files
tamayocrisgie
 
PPTX
some leadership theories MBA management.pptx
rkseo19
 
PDF
Buy Verified Coinbase Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
PPTX
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
PPTX
AI presentation for everyone in every fields
dodinhkhai1
 
PDF
The Family Secret (essence of loveliness)
Favour Biodun
 
PDF
Buy Verified Payoneer Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
PPTX
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
PDF
From Draft to DSN - How to Get your Paper In [DSN 2025 Doctoral Forum Keynote]
vschiavoni
 
PPTX
Inspired by VeinSense: Supercharge Your Hackathon with Agentic AI
ShubhamSharma2528
 
PDF
The Impact of Game Live Streaming on In-Game Purchases of Chinese Young Game ...
Shibaura Institute of Technology
 
PDF
Leveraging the Power of Jira Dashboard.pdf
siddharthshukla742740
 
PPTX
2025-07-06 Abraham 06 (shared slides).pptx
Dale Wells
 
PPTX
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
PPTX
STURGEON BAY WI AG PPT JULY 6 2025.pptx
FamilyWorshipCenterD
 
PDF
The Origin - A Simple Presentation on any project
RishabhDwivedi43
 
PPTX
presentation on legal and regulatory action
raoharsh4122001
 
Great-Books. Powerpoint presentation. files
tamayocrisgie
 
some leadership theories MBA management.pptx
rkseo19
 
Buy Verified Coinbase Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
AI presentation for everyone in every fields
dodinhkhai1
 
The Family Secret (essence of loveliness)
Favour Biodun
 
Buy Verified Payoneer Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
From Draft to DSN - How to Get your Paper In [DSN 2025 Doctoral Forum Keynote]
vschiavoni
 
Inspired by VeinSense: Supercharge Your Hackathon with Agentic AI
ShubhamSharma2528
 
The Impact of Game Live Streaming on In-Game Purchases of Chinese Young Game ...
Shibaura Institute of Technology
 
Leveraging the Power of Jira Dashboard.pdf
siddharthshukla742740
 
2025-07-06 Abraham 06 (shared slides).pptx
Dale Wells
 
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
STURGEON BAY WI AG PPT JULY 6 2025.pptx
FamilyWorshipCenterD
 
The Origin - A Simple Presentation on any project
RishabhDwivedi43
 
presentation on legal and regulatory action
raoharsh4122001
 

Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter

  • 2. Lambdas & Streams In JDK8 Making Bulk Opera/ons Simple Simon Ri6er Head of Java Technology Evangelism Oracle Corp. Twi6er: @speakjava Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
  • 3. Safe Harbor Statement The following is intended to outline our general product direcTon. It is intended for informaTon purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or funcTonality, and should not be relied upon in making purchasing decisions. The development, release, and Tming of any features or funcTonality described for Oracle’s products remains at the sole discreTon of Oracle. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 3
  • 4. java.util.concurrent (jsr166) 1.0 5.0 6 7 8 1996 … 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. java.lang.Thread Fork/Join Framework (jsr166y) Concurrency in Java Project Lambda Phasers, etc (jsr166)
  • 5. Lambdas In Java Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
  • 6. The Problem: External IteraTon List<Student> students = ... double highestScore = 0.0; for (Student s : students) { if (s.getGradYear() == 2011) { if (s.getScore() > highestScore) highestScore = s.score; } } • Our code controls iteraTon • Inherently Copyright © 2014, Oracle and/or its affiliates. All rights reserved. serial: iterate from beginning to end • Not thread-­‐safe • Business logic is stateful • Mutable accumulator variable
  • 7. Internal IteraTon With Inner Classes • IteraTon handled by the library • Not inherently serial – traversal Copyright © 2014, Oracle and/or its affiliates. All rights reserved. may be done in parallel • Traversal may be done lazily – so one pass, rather than three • Thread safe – client logic is stateless • High barrier to use – SyntacTcally ugly More FuncTonal double highestScore = students .filter(new Predicate<Student>() { public boolean op(Student s) { return s.getGradYear() == 2011; } }) .map(new Mapper<Student,Double>() { public Double extract(Student s) { return s.getScore(); } }) .max();
  • 8. Internal IteraTon With Lambdas Copyright © 2014, Oracle and/or its affiliates. All rights reserved. List<Student> students = ... double highestScore = students .filter(Student s -­‐> s.getGradYear() == 2011) .map(Student s -­‐> s.getScore()) .max(); • More readable • More abstract • Less error-­‐prone NOTE: This is not JDK8 code
  • 9. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Lambda Expressions Some Details • Lambda expressions represent anonymous funcTons – Same structure as a method • typed argument list, return type, set of thrown excepTons, and a body – Not associated with a class • We now have parameterised behaviour, not just values double highestScore = students. filter(Student s -­‐> s.getGradYear() == 2011). map(Student s -­‐> s.getScore()) max(); What How
  • 10. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Lambda Expression Types • Single-­‐method interfaces are used extensively in Java – DefiniTon: a func2onal interface is an interface with one abstract method – Func2onal interfaces are idenTfied structurally – The type of a lambda expression will be a func2onal interface • Lambda expressions provide implementaTons of the abstract method interface Comparator<T> { boolean compare(T x, T y); } interface FileFilter { boolean accept(File x); } interface Runnable { void run(); } interface ActionListener { void actionPerformed(…); } interface Callable<T> { T call(); }
  • 11. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Local Variable Capture • Lambda expressions can refer to effec2vely final local variables from the enclosing scope • EffecTvely 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 void expire(File root, long before) { root.listFiles(File p -­‐> p.lastModified() <= before); }
  • 12. What Does ‘this’ Mean For Lambdas? • ‘this’ refers to the enclosing object, not the lambda itself Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Think of ‘this’ as a final predefined local • Remember the Lambda is an anonymous func2on – It is not associated with a class – Therefore there can be no ‘this’ for the Lambda
  • 13. Referencing Instance Variables Which are not final, or effecTvely final Copyright © 2014, Oracle and/or its affiliates. All rights reserved. class DataProcessor { private int currentValue; public void process() { DataSet myData = myFactory.getDataSet(); dataSet.forEach(d -­‐> d.use(currentValue++)); } }
  • 14. Referencing Instance Variables The compiler helps us out Copyright © 2014, Oracle and/or its affiliates. All rights reserved. class DataProcessor { private int currentValue; public void process() { DataSet myData = myFactory.getDataSet(); dataSet.forEach(d -­‐> d.use(this.currentValue++); } } ‘this’ (which is effecTvely final) inserted by the compiler
  • 15. static T void sort(List<T> l, Comparator<? super T> c); List<String> list = getList(); Collections.sort(list, (String x, String y) -­‐> x.length() -­‐ y.length()); Collections.sort(list, (x, y) -­‐> x.length() -­‐ y.length()); Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Type Inference • The compiler can oien infer parameter types in a lambda expression § Inferrence based on the target funcTonal interface’s method signature • Fully staTcally typed (no dynamic typing sneaking in) – More typing with less typing
  • 16. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Method References • Method references let us reuse a method as a lambda expression FileFilter x = File f -­‐> f.canRead(); FileFilter x = File::canRead;
  • 17. Factory<List<String>> f = () -­‐> return new ArrayList<String>(); Replace with Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Constructor References • Same concept as a method reference – For the constructor Factory<List<String>> f = ArrayList<String>::new;
  • 18. Library EvoluTon Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
  • 19. int heaviestBlueBlock = blocks .filter(b -­‐> b.getColor() == BLUE) .map(Block::getWeight) .reduce(0, Integer::max); Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Library EvoluTon Goal • Requirement: aggregate operaTons on collecTons – New methods required on CollecTons to facilitate this • This is problemaTc – Can’t add new methods to interfaces without modifying all implementaTons – Can’t necessarily find or control all implementaTons
  • 20. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. SoluTon: Default Methods • Specified in the interface • From the caller’s perspecTve, just an ordinary interface method • Provides a default implementaTon • Default only used when implementaTon classes do not provide a body for the extension method • ImplementaTon classes can provide a be6er version, or not interface Collection<E> { default Stream<E> stream() { return StreamSupport.stream(spliterator()); } }
  • 21. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Virtual Extension Methods Stop right there! • Err, isn’t this implemenTng mulTple inheritance for Java? • Yes, but Java already has mulTple inheritance of types • This adds mulTple inheritance of behavior too • But not state, which is where most of the trouble is • Can sTll be a source of complexity • Class implements two interfaces, both of which have default methods • Same signature • How does the compiler differenTate? • StaTc methods also allowed in interfaces in Java SE 8
  • 22. FuncTonal Interface DefiniTon Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Single Abstract Method (SAM) type • A funcTonal interface is an interface that has one abstract method – Represents a single funcTon contract – Doesn’t mean it only has one method • @FunctionalInterface annotaTon – Helps ensure the funcTonal interface contract is honoured – Compiler error if not a SAM
  • 23. Lambdas In Full Flow: Streams Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
  • 24. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Aggregate OperaTons • Most business logic is about aggregate operaTons – “Most profitable product by region” – “Group transacTons by currency” • As we have seen, up to now, Java uses external iteraTon – Inherently serial – FrustraTngly imperaTve • Java SE 8’s answer: The Stream API – With help from Lambdas
  • 25. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Stream Overview At The High Level • AbstracTon for specifying aggregate computaTons – Not a data structure – Can be infinite • Simplifies the descripTon of aggregate computaTons – Exposes opportuniTes for opTmisaTon – Fusing, laziness and parallelism
  • 26. Source Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Stream Overview • A stream pipeline consists of three types of things – A source – Zero or more intermediate operaTons – A terminal operaTon • Producing a result or a side-­‐effect Pipeline int total = transactions.stream() .filter(t -­‐> t.getBuyer().getCity().equals(“London”)) .mapToInt(Transaction::getPrice) .sum(); Intermediate operaTon Terminal operaTon
  • 27. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Stream Sources Many Ways To Create • From collecTons and arrays – Collection.stream() – Collection.parallelStream() – Arrays.stream(T array) or Stream.of() • StaTc factories – IntStream.range() – Files.walk() • Roll your own – java.util.Spliterator
  • 28. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Stream Sources Provide • Access to stream elements • DecomposiTon (for parallel operaTons) – Fork-­‐join framework • Stream characterisTcs – ORDERED – SORTED – DISTINCT – SIZED – NONNULL – IMMUTABLE – CONCURRENT
  • 29. Stream Terminal OperaTons Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • The pipeline is only evaluated when the terminal operaTon is called – All operaTons can execute sequenTally or in parallel – Intermediate operaTons can be merged • Avoiding mulTple redundant passes on data • Short-­‐circuit operaTons (e.g. findFirst) • Lazy evaluaTon – Stream characterisTcs help idenTfy opTmisaTons • DISTINT stream passed to distinct() is a no-­‐op
  • 30. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Maps and FlatMaps Map Values in a Stream Map FlatMap Input Stream Input Stream 1-­‐to-­‐1 mapping 1-­‐to-­‐many mapping Output Stream Output Stream
  • 31. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Optional<T> Reducing NullPointerException Occurrences String direction = gpsData.getPosition().getLatitude().getDirection(); String direction = “UNKNOWN”; if (gpsData != null) { Position p = gpsData.getPosition(); if (p != null) { Latitude latitude = p.getLatitude(); if (latitude != null) direction = latitude.getDirection(); } }
  • 32. NullPointerException Occurrences Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Optional<T> Reducing • Indicates that reference may, or may not have a value – Makes developer responsible for checking – A bit like a stream that can only have zero or one elements Optional<GPSData> maybeGPS = Optional.ofNullable(gpsData); maybeGPS.ifPresent(GPSData::printPosition); GPSData gps = maybeGPS.orElse(new GPSData()); maybeGPS.filter(g -­‐> g.lastRead() < 2).ifPresent(GPSData.display());
  • 33. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Example 1 Convert words in list to upper case List<String> output = wordList .stream() .map(String::toUpperCase) .collect(Collectors.toList());
  • 34. Example 1 Convert words in list to upper case (in parallel) List<String> output = wordList .parallelStream() .map(String::toUpperCase) .collect(Collectors.toList()); Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
  • 35. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Example 2 • BufferedReader has new method – Stream<String> lines() Count lines in a file long count = bufferedReader .lines() .count();
  • 36. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Example 3 Join lines 3-­‐4 into a single string String output = bufferedReader .lines() .skip(2) .limit(2) .collect(Collectors.joining());
  • 37. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Example 4 Collect all words in a file into a list List<String> output = reader .lines() .flatMap(line -­‐> Stream.of(line.split(REGEXP))) .filter(word -­‐> word.length() > 0) .collect(Collectors.toList());
  • 38. Example 5 List of unique words in lowercase, sorted by length List<String> output = reader .lines() .flatMap(line -­‐> Stream.of(line.split(REGEXP))) .filter(word -­‐> word.length() > 0) .map(String::toLowerCase) .distinct() .sorted((x, y) -­‐> x.length() -­‐ y.length()) .collect(Collectors.toList()); Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
  • 39. Example 6: Real World Infinite stream from thermal sensor private int double currentTemperature; ... thermalReader .lines() .mapToDouble(s -­‐> Double.parseDouble(s.substring(0, s.length() -­‐ 1))) .map(t -­‐> ((t – 32) * 5 / 9) .filter(t -­‐> t != currentTemperature) .peek(t -­‐> listener.ifPresent(l -­‐> l.temperatureChanged(t))) .forEach(t -­‐> currentTemperature = t); Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
  • 40. Example 6: Real World Infinite stream from thermal sensor private int double currentTemperature; ... thermalReader .lines() .mapToDouble(s -­‐> Double.parseDouble(s.substring(0, s.length() -­‐ ))) .map(t -­‐> ((t – 32) * 5 / 9) .filter(t -­‐> t != this.currentTemperature) .peek(t -­‐> listener.ifPresent(l -­‐> l.temperatureChanged(t))) .forEach(t -­‐> this.currentTemperature = t); Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
  • 41. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Conclusions • Java needs lambda statements – Significant improvements in exisTng libraries are required • Require a mechanism for interface evoluTon – SoluTon: virtual extension methods • Bulk operaTons on CollecTons – Much simpler with Lambdas • Java SE 8 evolves the language, libraries, and VM together
  • 42. Simon Ri6er Oracle CorporarTon Twi6er: @speakjava Copyright © 2014, Oracle and/or its affiliates. All rights reserved.