Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

State of the Lambda

DZone's Guide to

State of the Lambda

· Java Zone
Free Resource

Try Okta to add social login, MFA, and OpenID Connect support to your Java app in minutes. Create a free developer account today and never build auth again.

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/

Build and launch faster with Okta’s user management API. Register today for the free forever developer edition!

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}