4. Pourquoi cette présentation
(au PSUG ?)
!!! DISCLAIMER !!!
● Pas de troll
● Ni monade, ni typeclass
● Pas de conflit d'intérêt
● Vous avez le droit de parler aux chauffeurs
5. À venir
● Présentation de concepts
● Faire des trucs avec les concepts
● Parler des concepts
10. (Anonymous) Inner Class
Une Solution λ
adults = Iterables.filter(persons,
new Predicate<Person>() {
@Override
public boolean apply(Person person) {
return person.getAge() >= 18;
}
}); // Java + Guava
11. (Anonymous) Inner Class
Une Solution λ
adults = Iterables.filter(persons,
new Predicate<Person>() {
@Override
public boolean apply(Person person) {
return person.getAge() >= 18;
}
}); // Java + Guava
12. (Anonymous) Inner Class
(Pas Vraiment) Une Solution λ
● "The pain of anonymous inner classes makes us roll
our eyes in the back of our heads every day." (a wise
Oracle's client - 01/2011)
Average length of Java one-liner is 21 line!
@DEVOPS_BORAT - 12/09/2011
13. λ Project Date and Time
(JSR 335) API (JSR 310) Project Coin
Nashorn
(JSR ?)
Performance Productivité
Annotation on
Types (JSR 308)
Java 8
(JSR 337)
Project Jigsaw Modularité
(JSR ?) Java 9
14. [New]
Method Reference [New] Interface Method
[New] T::m T::new default void m()...
x -> f(x) obj::m
Virtual
λ Expression Change in Extension
Property
Inheritance Method
Type Inference [New]
Engine Static Method in
Enhancement Interface
λ Project
(JSR 335)
Collection
[New]
API Extension Parallel Collections
19. D'autres formes de λ
x -> 2 * x
() -> 42
m -> {
m.put("France", "Paris");
m.put("UK", "London");
m.put("USA", "Washington");
}
20. Inner Class vs λ Solution
Iterables.filter(persons,
new Predicate<Person>() {
@Override
public boolean apply(Person p) {
return p.getAge() >= 18;
}
}); // Java 5-7 + Guava
Iterables.filter(persons, // Java 8 + Guava
person -> person.getAge() >= 18);
21.
22. λ = SAM
(Single Abstract Method)
● Indépendant du type
● Une et une seule méthode abstraite
● Fonctionne avec
○ Runnable, Callable, Comparator
○ JDK's function API, Guava API
○ types persos, ...
23. λ et variables externes
int x = 1; => Implicitement final
y -> y + x;
x = 2;
24. Method Reference
String::valueOf
// like: v -> String.valueOf(v)
String::new
// like: v -> new String(v)
myBigDecimal::add
// like: (n) -> myBigDecimal.add(n)
Arrays.sort(myInts, Integer::compare)
27. VEM : Dangereux ?
● Brian Goetz : NON
○ Héritage de comportement uniquement
● François Sarradin : OUI O_O'
○ Article : "Java 8: Now You Have Mixins?"
○ (Voir les kata)
28. Faire évoluer les APIs
● "APIs need a mechanism for evolving, or they will
become increasingly constraining to use, and replacing
them is expensive." (Brian Goetz - 07/2012)
31. Java 8
Sites Web
Java SE 8 Early Access (with lambda)
http://jdk8.java.net/lambda/
Mercurial repo
http://hg.openjdk.java.net/lambda/lambda
Mailing List
mailto:lambda-dev@openjdk.java.net
http://mail.openjdk.java.net/pipermail/lambda-dev/