Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Lamdba expressions in java

Shulou Source: shulou.com Published: 2022-05-31 10:48:17 10月03日 Update

This article introduces the knowledge of "how to use Lamdba expressions in java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. If only one parameter is needed for Lamdba, parentheses can be omitted

Consumer con = str-> {System.out.println (str)}

2. Lamdba requires a parameter, but no return value is returned

Consumer con = (String str)-> {System.out.println (str)}

3. Data types can be omitted.

Because it can be inferred by the compiler, it is called type inference

Consumer con = (str)-> {System.out.println (str)}

4. Lamdba requires more than two parameters.

Multiple execution statements, and can have return values

Comparatorcom = (o1memo1)-> {Syste.out.println ("Lamdba expressions are used"); return Integer.compare (o1Powero2);} "how to use Lamdba expressions in java" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Expressions parameters content more knowledge types inference practicality achievement next two dilemma multiple actual situation parentheses data articles cases editing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Xiaomi vpn Shulou Tech Info OPPO Reno