• Post Reply Bookmark Topic Watch Topic
  • New Topic

Lambda expressions - Rationale and examples found here  RSS feed

 
Rick Goff
Ranch Hand
Posts: 54
Clojure Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
Clojure Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!).
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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').
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!