13. What I’m hoping for
A discussion
Making things a tad more clear
4-b
14. What I’m hoping for
A discussion
Making things a tad more clear
... or just less overlooked ?
4-c
15. What I’m hoping for
A discussion
Making things a tad more clear
... or just less overlooked ?
Not too boring
4-d
16. What (functional, new things) you can do with Java 8
Lambda-expressions
(String first, String second) ->
Integer.compare(first.length(), second.length)
Functional Interfaces
Runnable r = () -> System.out.println("I am Runnable!");
Method references
button.setOnAction(System.out::println);
Constructor references
List<String> labels = ... ;
Stream<Button> buttonsStream = labels.stream().map(Button::new);
Buttons[] buttonsArray = labels.stream().toArray(Button::new);
int[]::new;
5
17. The devil is in the details
Optional<T>, Optional.of(), Optional.ofNullable(), Optional.empty()
Default methods in interfaces.
list.forEach(System.out::println)
... beware: SuperClasses win, Interfaces clash. ... And the standard library was not
entirely rewritten (Path/Paths)
Important topics : variable capture in closures, parallel execution.
int[] counter = new int[1];
button.setOnAction(event -> counter[0]++);
6
18. And also, Streams
Any Collection has a stream()
Stream.of() with a vararg, an array
filter, map, flatMap, as well as plumbing: split, concat, limit
Lazy processing, parallel() processing (you enforce statelessness)
terminal reductions, e.g. reduce
collector:
HashSet<String> result =
stream.collect(HashSet::new, HashSet::add, HashSet::addAll)
Collector implementations (toList, toMap, ...)
counting, maxBy, groupinBy, mapping, ...
Beware: think about reuse.
7
22. Interlude
Does that make Java a functional programming language ?
First class functions
Technicalities
8-c
23. Interlude
Does that make Java a functional programming language ?
First class functions
Technicalities
Does that make Java a Scala competitor ?
8-d
24. Interlude
Does that make Java a functional programming language ?
First class functions
Technicalities
Does that make Java a Scala competitor ?
Scala has never had a feature poverty problem.
8-e
25. What you can’t do with Java 8 (yet)
1. Case classes
2. Pattern matching
3. Tail call elimination
4. Scoped access
5. Lazy keyword
6. Traits (well-scoped)
7. Rich Imports (local, aliased)
8. Macros
9. Backend (Miguel Garcia)
10. Specialization (Vlad Ureche)
11. Value classes
12. Implicits
13. Cake !
9