Your SlideShare is downloading. ×
0
Project Lambda  or #()(”Project Lambda”) 2010-04-29
Lambda Expressions (aka Closures) <ul><li>“ a first-class function with free variables that are bound in the lexical envir...
Lambda Expressions – Suggested Syntax <ul><li>A new way of writing anonymous functions </li></ul><ul><li>A functions which...
Lambda Expressions <ul><li>Complex expressions </li></ul>#(int x, int y){ int z = expensiveComputation(x, y);  if (z < 0) ...
Function Types <ul><li>Every expression in Java must have a type, i.e. introduce  function types </li></ul><ul><li>… and t...
Functions as arguments <ul><li>Methods can take a function as an argument </li></ul>public int[] map(int[] a, #int(int) fn...
SAM types <ul><li>Interfaces with just one method (SAM) </li></ul>Thread th = new Thread(new Runnable() {  public void run...
Variable Capture shared  int count = 0;  Collections.sort(data, #(String a, String b){  count++;  return a.length() - b.le...
Upcoming SlideShare
Loading in...5
×

Project Lambda - Closures after all?

1,131

Published on

Will it be closures in Java 7 after all?

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,131
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Project Lambda - Closures after all?"

  1. 1. Project Lambda or #()(”Project Lambda”) 2010-04-29
  2. 2. Lambda Expressions (aka Closures) <ul><li>“ a first-class function with free variables that are bound in the lexical environment” - Wikipedia </li></ul><ul><li>HUGE debate about various closures decision earlier BGGA, CICE, FCM, … </li></ul><ul><li>Oracle seems to have decided this without JSR/JCP - most likely that this will be included in Java 7 </li></ul><ul><li>Straw-Man Proposol - first-class functions - function types - lambda expression </li></ul><ul><li>Syntax and content not definite, may change </li></ul><ul><li>Complexity budget reached? </li></ul>
  3. 3. Lambda Expressions – Suggested Syntax <ul><li>A new way of writing anonymous functions </li></ul><ul><li>A functions which take an int and returns its double </li></ul>#() (42) //no args, returns 42 #(int x) (x+x)
  4. 4. Lambda Expressions <ul><li>Complex expressions </li></ul>#(int x, int y){ int z = expensiveComputation(x, y); if (z < 0) return x; if (z > 0) return y; return 0; }
  5. 5. Function Types <ul><li>Every expression in Java must have a type, i.e. introduce function types </li></ul><ul><li>… and they could be invoked </li></ul>#int() fortyTwo = #()(42); #int(int) doubler = #(int x)(x + x); assert fortyTwo() == 42; assert doubler(fortyTwo()) == 84;
  6. 6. Functions as arguments <ul><li>Methods can take a function as an argument </li></ul>public int[] map(int[] a, #int(int) fn) { int[] b = new int[a.length]; for (int i = 0; i < a.length; i++) b[i] = fn(a[i]); return b; }
  7. 7. SAM types <ul><li>Interfaces with just one method (SAM) </li></ul>Thread th = new Thread(new Runnable() { public void run() { doSomeStuff(); doMoreStuff(); } }); Thread th = new Thread(#(){ doSomeStuff(); doMoreStuff(); } )
  8. 8. Variable Capture shared int count = 0; Collections.sort(data, #(String a, String b){ count++; return a.length() - b.length()}); System.out.println(count);
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×