Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the grammatical changes in Java 8

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "what is the change in the grammar of Java 8". The content is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "what are the changes in the grammar of Java 8?"

With the official release of Java 7 SE (Standard Edition), members of Oracle and the Java Community process Organization (JCP) have begun to carefully consider what features to add to Java SE 8, the next version of the programming language. The work that will be put on the agenda for Java 8 some time ago is to design Java for cloud computing. Recently, another grammatical change has been proposed for Java 8: Java 8 will adopt the same Lambda syntax as C #.

Lambda-dev announced on the mailing list that Java's Lambda syntax is based on the C # syntax. This syntax has been used for a long time in the C # language (C # introduced delegate types in 1. 0 and supports anonymous functions in 2. 0 and Lambda expressions in 3. 0).

This syntax supports both expressions and code blocks. The form of the expression does not require curly braces and returns the result after execution. The form of a grammatical block requires curly braces, and the result is not returned directly unless the return keyword is used. Examples are also given in the email:

The syntax of C # is:

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

Here are some examples of using the syntax of lambda expressions:

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

The key advantage of Lambda expressions is that they type-infer parameters. However, in some cases, the compiler still cannot infer the correct type (especially when operator overloading occurs, for example: (x, y) = > x + y when the Java compiler does not know whether x and y are int or double). In general, type inference engines automatically produce the correct code, and programmers can always add type information explicitly if more prompts are needed.

The above is all the contents of the article "what are the changes in the grammar of Java 8"? thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report