• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Core Java question: benefits of lambda expressions

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the most significant benefits of lambda expressions?
 
author
Posts: 284
35
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, there are two ways of looking at that. From a purely practical perspective, you don't have to do as much typing. For example,



is less typing than



But I like to think about it more philosophically. The lambda syntax better expresses the intent of the programmer. When I have a task, then I think "when it is invoked, then call doWork 1000 times". I do not think that I want to create an anonymous class that implements the Runnable interface whose run method does ...". All that stuff with the anonymous class and the interface and the run method is just implementation detail. With the old way, the detail drowned out the important part. With lambda expressions, the unimportant part fades in the background, and you write and read the code that matters.

Cheers,

Cay
 
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think one big advantage is the functional programming you can achieve. You can now create functional libraries and use individual methods as needed. For example:



Now, you can move Helper to some other .jar file and recompile as needed if the logic changes, and leave your original code in App{} unchanged.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic