Srikanth Sankaran IBM India Stephan Herrmann GK Software Noopur Gupta IBM India EclipseCon NA 2014 JDT Embraces Lambda Expressions 1
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 EclipseCon NA 2014 JDT Embraces Lambda Expressions 2
3
4
5
6
7
8
9
LambdaExpression ::= LambdaParameters '->' LambdaBody LambdaParameters -> BeginLambda LambdaParameterList LambdaParameterList -> '(' FormalParameterListopt ') LambdaBody -> Expression LambdaBody -> Block I i = BeginLambda (x) -> { }; EclipseCon NA 2014 JDT Embraces Lambda Expressions 10
11
12
13
14
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. EclipseCon NA 2014 JDT Embraces Lambda Expressions 15
16
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 EclipseCon NA 2014 JDT Embraces Lambda Expressions 17
18
19
20
Collectors.<Person,String,Integer>toMap(..) Collectors.toMap(..) Collector<String,Integer> coll = new MyCollector<>(); EclipseCon NA 2014 JDT Embraces Lambda Expressions 21
22
23
24
25
26
27
28
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 EclipseCon NA 2014 JDT Embraces Lambda Expressions 29
30
31
Ctrl + 1 Enter EclipseCon NA 2014 JDT Embraces Lambda Expressions 32
Ctrl + 1 Enter EclipseCon NA 2014 JDT Embraces Lambda Expressions 33
Ctrl + 1 Enter EclipseCon NA 2014 JDT Embraces Lambda Expressions 34
Ctrl + 1 Enter EclipseCon NA 2014 JDT Embraces Lambda Expressions 35
36
Lambda Expression: Method Reference: EclipseCon NA 2014 JDT Embraces Lambda Expressions 37
Demo Examples: EclipseCon NA 2014 JDT Embraces Lambda Expressions 38
39
40
41
42
43
44
45
46
47
Far too risky to cram late into 8 (Nov 2013) EclipseCon NA 2014 JDT Embraces Lambda Expressions 48
List <: List<String>? Raw types EclipseCon NA 2014 JDT Embraces Lambda Expressions 49
Problem detected during type inference:... EclipseCon NA 2014 JDT Embraces Lambda Expressions 50
51
52
53
54
55
56
57
58
59
Dramatis personæ - The usual suspects Andy Clement Steve Francisco Michael Rennie Olivier Thomann Curtis Windatt Walter Harley David Williams Jesper S. Møller Stephan Herrmann Markus Keller Dani Megert Jay Arthanareeswaran Deepak Azad Shankha Banerjee Anirban Chakarborty Vikas Chandra Noopur Gupta Ayushman Jain Manju Mathew Manoj Palat Srikanth Sankaran Sarika Sinha EclipseCon NA 2014 JDT Embraces Lambda Expressions 60
61
EVALUATE THIS SESSION 1 Sign-in: www.eclipsecon.org 2 Select session from schedule 3 Evaluate: