This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Features new in Java 8 and the fly likes Lambda expressions - Rationale and examples found here Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Features new in Java 8
Bookmark "Lambda expressions - Rationale and examples found here" Watch "Lambda expressions - Rationale and examples found here" New topic
Author

Lambda expressions - Rationale and examples found here

Rick Goff
Ranch Hand

Joined: Nov 14, 2006
Posts: 54

For folks who are just wondering what this JSR is about, you might want to have a look at Brian Goetz's informal overview, found here:

Brian Goetz's overview of JSR-335 (December 2011)

He is the captain of the project, besides a very good writer.

HTH,
Rick


OCPJP 6
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38515
    
  23
There is a more recent version here, also by Brian Goetz. That makes fascinting reading, and I haven't read it all yet. It has some things I had never seen before, including the List#stream method and comparing methods in the Comparator interface. Those methods appear to be static, which is something I had never seen before.
Actually the stream method appears to belong to Collection.
Rick Goff
Ranch Hand

Joined: Nov 14, 2006
Posts: 54

Here's the link to the latest version:

http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-final.html

Oops, sorry Campbell. Just saw you had already included the link.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Campbell Ritchie wrote:Those methods appear to be static, which is something I had never seen before.

Static and default methods in interfaces are new in Java 8. The first is pretty obvious, the second means you can add a method to an interface with a default implementation. Collection.stream() is one such method. This adds great flexibility in extending existing interfaces; you no longer need to worry about implementing classes breaking because they will simply inherit the default implementation from the interface (that's right - inheriting from an interface!).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38515
    
  23
Does that mean that Java8 interfaces work rather like abstract classes?
Does that mean that Java8 classes can inherit implemented methods from two interfaces?
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3013
    
  10
Campbell Ritchie wrote:Does that mean that Java8 interfaces work rather like abstract classes?

Somewhat, yes. The details are different, but they both can contain partial implementations.

Campbell Ritchie wrote:Does that mean that Java8 classes can inherit implemented methods from two interfaces?

Yes. However, they can inherit only one implementation of a particular method signature. They have rules for resolving any apparent conflicts.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38515
    
  23
I hope that mean there will be a new JLS with those disambiguation rules in. I see the keyword default has a new use, too. It is in the Brian Goetz link I posted.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3013
    
  10
Campbell Ritchie wrote:I hope that mean there will be a new JLS with those disambiguation rules in.

Sure. They always do that for significant language changes, and Java 8 has some of the biggest they've ever had. You can see the text of proposed JLS changes in the Early Draft Specification link provided in the Goetz article, third sentence.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3827

With the changes to core libraries/interfaces like the default methods in collections interfaces etc...
Lambda is the single largest upgrade to the model in Java stated by Mark Reinhold (even larger than generics').


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lambda expressions - Rationale and examples found here