Page 1
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
1
Srikanth SankaranIBM India
Stephan HerrmannGK Software
Noopur Gupta
IBM India
Page 2
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
2
Java 8 features:
JSR335 - Project Lambda
Lambda Expressions & Method References
Extensions to
Overload resolution & Type inference
Support for “code carrying” interface methods.
JSR308 - Type Annotations
JEP120 - Repeating Annotations
JEP118 - Method Parameter Reflection
JSR269 - Pluggable Annotation Processor API &
javax.lang.model API enhancements for Java 8
Page 3
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
3
Page 4
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
4
Page 5
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
5
Page 6
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
6
Page 7
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
7
Page 8
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
8
Page 9
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
9
Page 10
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
10
LambdaExpression ::= LambdaParameters '->' LambdaBody
LambdaParameters -> BeginLambda LambdaParameterList
LambdaParameterList -> '(' FormalParameterListopt ')„
LambdaBody -> Expression
LambdaBody -> Block
I i = BeginLambda (x) -> { };
Page 11
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
11
Page 12
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
12
Page 13
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
13
Page 14
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
14
Page 15
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
15
Scanning + Parsing => Parse tree
+ Resolution => Resolved parse tree
+ Data/control flow analysis => Flow analyzed parse tree
+ Code generation => Class files.
() -> { throw new Exception(); } is void and value compatible.
Page 16
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
16
Page 17
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
17
o Changes the very notion of a type.
o Some subsystems should view @NonNull String != @ReadOnly String
o while others should view them as being the same.
o Abstractions need to support either world view efficiently.
String is a String is a String
Page 18
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
18
Page 19
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
19
Page 20
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
20
Page 21
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
21
Collectors.<Person,String,Integer>toMap(..)
Collectors.toMap(..)
Collector<String,Integer> coll = new MyCollector<>();
Page 22
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
22
Page 23
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
23
Page 24
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
24
Page 25
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
25
Page 26
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
26
Page 27
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
27
Page 28
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
28
Page 29
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
29
Recipe for disaster:● implement java.util.List → compile against JRE 7 → OK
● upgrade to JRE 8 but compile as 1.7
Undefined compiler behavior● 1.7 compiler cannot handle default methods (from .class)
● exact answer depends on compiler implementation details
● there is no specification
● ecj and javac differ
● assimilation is difficult
Page 30
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
30
Page 31
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
31
Page 32
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
Enter
+Ctrl 1
32
Page 33
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
33
Enter
+Ctrl 1
Page 34
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
34
Enter
+Ctrl 1
Page 35
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
35
Enter
+Ctrl 1
Page 36
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
36
Page 37
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
37
Lambda Expression:
Method Reference:
Page 38
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
38
Demo
Examples:
Page 39
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
39
Page 40
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
40
Page 41
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
41
Page 42
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
42
Page 43
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
43
Page 44
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
44
Page 45
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
45
Page 46
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
46
Page 47
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
47
Page 48
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
48
Far too risky to
cram late into 8
(Nov 2013)
Page 49
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
49
List <: List<String> ?
Raw types
Page 50
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
50
“Problem detected during type inference: ...”
Page 51
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
51
Page 52
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
52
Page 53
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
53
Page 54
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
54
Page 55
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
55
Page 56
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
56
Page 57
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
57
Page 58
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
58
Page 59
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
59
Page 60
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
60
Dramatis personæ - The usual suspects
Jay Arthanareeswaran
Deepak Azad
Shankha Banerjee
Anirban Chakarborty
Vikas Chandra
Noopur Gupta
Ayushman Jain
Manju Mathew
Manoj Palat
Srikanth Sankaran
Sarika Sinha
Jesper S. Møller
Stephan Herrmann
Markus Keller
Dani Megert
Andy Clement
Steve Francisco
Michael Rennie
Olivier Thomann
Curtis Windatt
Walter Harley
David Williams
Page 61
EclipseCon NA 2014 | JDT Embraces Lambda Expressions
61
Page 62
EVALUATE THIS SESSION
Sign-in: www.eclipsecon.org
Select session from schedule
Evaluate:
1
2
3