DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Event-Driven Fractals
  • DZone Community Awards 2022
  • Easily Update and Reload SSL for a Server and an HTTP Client
  • Practical Guide: Anorm Using MySQL With Scala

Trending

  • The State of Data Streaming for Digital Natives (Born in the Cloud)
  • OneStream Fast Data Extracts APIs
  • Build a Digital Collectibles Portal Using Flow and Cadence (Part 1)
  • How to Migrate Vector Data from PostgreSQL to MyScale
  1. DZone
  2. Coding
  3. Languages
  4. Java 8 Lambda syntax (closures) is decided. It's similar to C# and Scala

Java 8 Lambda syntax (closures) is decided. It's similar to C# and Scala

Mitch Pronschinske user avatar by
Mitch Pronschinske
·
Sep. 12, 11 · News
Like (0)
Save
Tweet
Share
34.88K Views

Join the DZone community and get the full member experience.

Join For Free
Looks like Brian Goetz and the JDK just made a major syntax decision for closures (lambdas) in Java 8: 
This just in: the EG has (mostly) made a decision on syntax.

After considering a number of alternatives, we decided to essentially 
adopt the C# syntax.  We may still deliberate further on the fine points 
(e.g., thin arrow vs fat arrow, special nilary form, etc), and have not 
yet come to a decision on method reference syntax.

The C# syntax is:

   lambda = ArgList Arrow Body
   ArgList = Identifier
             | "(" Identifier [ "," Identifier ]* ")"
             | "(" Type Identifier [ "," Type Identifier ]* ")"
   Body = Expression
             | "{" [ Statement ";" ]+ "}"

Here are some examples of lambda expressions using this syntax:

   x => x + 1
   (x) => x + 1
   (int x) => x + 1
   (int x, int y) => x + y
   (x, y) => x + y
   (x, y) => { System.out.printf("%d + %d = %d%n", x, y, x+y); }
   () => { System.out.println("I am a Runnable"); }

The decision to choose this syntax was twofold:
  - The syntax scores "pretty well" on most subjective measures (though 
has cases where it looks bad, just like all the others do).  In 
particular, it does well with "small" lambdas that are used as method 
arguments (a common case), and also does well with large 
(multi-statement) lambdas.

  - Despite extensive searching, there was no clear winner among the 
alternatives (each form had some good aspects and some really not very 
good aspects, and there was no form that was clearly better than the 
others).  So, we felt that it was better to choose something that has 
already been shown to work well in the two languages that are most like 
Java -- C# and Scala -- rather than to invent something new.

A compiler implementation should be available soon.

Thanks for the find Ray Hulha!

Java (programming language) Syntax (programming languages) Scala (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Event-Driven Fractals
  • DZone Community Awards 2022
  • Easily Update and Reload SSL for a Server and an HTTP Client
  • Practical Guide: Anorm Using MySQL With Scala

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: