Over a million developers have joined DZone.

State of the Lambda

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

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);

 

From http://www.baptiste-wicht.com/2010/07/state-of-the-lambda/

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}