State of the Lambda

Brian Goetz, from Oracle, has posted an updated proposal for the lambda expressions : State of the Lambda

Here are some examples of closures taken from the proposal :

We can use lambda expressions to replace the heavy usage of Single Abstract Method (SAM) interfaces :

public interface CallbackHandler { 
    public void callback(Context c);
}

CallbackHandler cb = { c -> System.out.println("pippo") };

We can make references to methods to use it as SAM interfaces :

class Person { 
    private final String name;
    private final int age;

    public static int compareByAge(Person a, Person b) { ... }
    public static int compareByName(Person a, Person b) { ... }
}

Person[] people = ...

Arrays.sort(people, #Person.compareByAge);

Related articles

  • Java 7 : Oracle pushes a first version of closures
  • Java 7 : Add "public defender methods" to Java interfaces
  • Java 7 has been released!
  • Java 7 Delays and Plan B
  • C++11 Concurrency - Part 1 : Start Threads
  • JDK 7 Features updated ! Plan B has apparently been approved
  • Comments

    Comments powered by Disqus