JSR 335: Project Lambda€¦ · JSR337 Java Roadmap Java 8 aug. 2013 Java 7 jul. 2011 Java 9? FP /...

Post on 29-May-2020

38 views 0 download

Transcript of JSR 335: Project Lambda€¦ · JSR337 Java Roadmap Java 8 aug. 2013 Java 7 jul. 2011 Java 9? FP /...

JSR 335:Project LambdaFrançois Sarradin -- Xebia

λ

JSR337

Java RoadmapJava 8

aug. 2013Java 7

jul. 2011 Java 9?

● FP / Parallel comp.● Date API improv.● Type annotation● Compact profiles● Nashorn

ModularityPerformanceProductivity

Project LambdaWhat's in it?

Project Lambda

JSR335

Collection API Bulk Operations

Lambda Expression Virtual Extension Method

Collection API Parallel CollectionsFunctional API

Question

What will be the impactof Project Lambdaon the Java world?

AnswerLook at Speed Car!

Planning...Presentation + live coding (free to interrupt)

● Genesis

● Lambda of Java

● Project Lambda

...And Then● Debate

● Retrospective (agile style!)

● Report○ Xebia blog○ Project Lambda ML

Genesis

More Processors

More ExpressivenessMore Readability

结果 汉字 = new 物().処理();

vs.

fact n = product [1..n]

Is it all Chinese to you?

FP & Competition

Guava

Clojure

C# / F#C++

(Anonymous) Inner ClassA λ Solution

Iterables.filter(persons, new Predicate<Person>() {

@Overridepublic boolean apply(Person person) {

return person.getAge() >= 18;}

}); // Java + Guava

This is what you really need!

Iterables.filter(persons, IS_ADULT);

Predicate<Person> IS_ADULT= new Predicate<Person>() {

@Overridepublic boolean apply(Person person) {

return person.getAge() >= 18;}

});

(Anonymous) Inner ClassA (better?) λ Solution

(Anonymous) Inner Class(Not Really) A λ Solution

Average length of Java one-liner is 21 line!@DEVOPS_BORAT - 12/09/2011

● "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)

What about Oracle?

● "It’s time to add closures to Java" (Mark Reinhold, 12/2009)

● "Oracle's position is that Java must evolve -- carefully, of course -- in order to remain competitive." (Brian Goetz - 08/2011)

Lambda of Java

Here is the λ!

(int x, int y) -> x + y

(x, y) -> x + y

(int x, int y) -> { return x + y; }

(x, y) -> { return x + y; }

Other λ forms

m -> {m.put("France", "Paris");m.put("UK", "London");m.put("USA", "Washington");

}

x -> 2 * x

() -> 42

Inner Classvs. λ SolutionIterables.filter(persons, new Predicate<Person>() {

@Overridepublic boolean apply(Person p) {

return p.getAge() >= 18;}

}); // Java 5-7 + Guava

Iterables.filter(persons, // Java 8 + Guavap -> p.getAge() >= 18);

Method Reference

String::valueOf// like: v -> String.valueOf(v)

Integer::compare// like: (i1, i2) -> Integer.compare(i1, i2)

Arrays.sort(myInts, Integer::compare)

Virtual Extension Method(VEM)

interface Message {

String getMessage() default {return "Look Ma'! Interface with code!";

}

}

VEMMotivation

Help to extend existing APIs

Minimize rewrite of existing API implementation

eg. Collection API

eg. Hibernate Collection Implementation

VEM

Collection API Extended

java.util.functions.*

java.util.streams.*

Extension of Iterable, Iterator, Collection, Map, ...

java.util.Optional

Parallel ComputingAs Easy as 1-2-3?

myCollection.parallel().filter(x -> ...).map(x -> ...).reduce((x, y) -> ...) // parallel

myCollection.stream().filter(x -> ...).map(x -> ...).reduce((x, y) -> ...) // sequential

Some kata and demos...

Project Lambda

The Dream Team ;)

photo: @crazybob

Web Sites

OpenJDK 8 Web sitehttp://openjdk.java.net/projects/lambda/

JSR335http://jcp.org/en/jsr/detail?id=335

Where to Get Java 8

Mercurial repohttp://hg.openjdk.java.net/lambda/lambda

Java SE 8 Early Access (with lambda)http://jdk8.java.net/lambda/

Mailing Lists

Technical Discussionmailto:lambda-dev@openjdk.java.nethttp://mail.openjdk.java.net/pipermail/lambda-dev/

Libs Spec Discussionhttp://mail.openjdk.java.net/pipermail/lambda-libs-spec-<*>/

Spec Discussionhttp://mail.openjdk.java.net/pipermail/lambda-spec-<*>/

Around Project Lambda

OpenJDK OSX Build (7 & 8)http://code.google.com/p/openjdk-osx-build/

Java 8 vs Scala: a Feature Comparisonhttp://www.infoq.com/articles/java-8-vs-scala

H. Gomez

U. PeterS. van den Berg

Around Project LambdaIn France

Curious about Project Lambda ;)http://blog.xebia.fr/ [FR]http://kerflyn.wordpress.com/

JDK 8: lambdas in Action [FR]http://www.devoxx.com/display/FR12/JDK+8+demo++lambdas+in+Action

Java 8 et les Lambda [FR]http://thecodersbreakfast.net/index.php?post/2012/05/30/Java-8-et-les-Lambda

G. Tardif

O. Croisier

Guess Who?

Project Lambdaand the Community● Transparency

○ Presentations / Publications○ Source code available

● Early testing by community○ Pre-version available○ AdoptOpenJDK (http://java.

net/projects/adoptopenjdk/pages/AdoptOpenJDK)

● Quick feedback○ ML, Hackdays

Question● Oneliner, Readability, and Debugability

● Java vs. Competitors

● What to do for Java 8 to be adopted in projects?

● Is there a future for Java?