In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces how to use lambda expression in java8, the content is very detailed, interested friends can refer to, hope to be helpful to you.
1.lambda indicates that it can be used everywhere. It is only used in functional interfaces.
2, for example, Chestnut has such an interface.
Public interface LumbdaTestinterface {String test (String name);}
What if I want an implementation object? The first method writes another class implementation interface and overrides the test method
The second method is to create an anonymous implementation class directly when you use it, such as this
LumbdaTestinterface lumbdaTestinterface= new LumbdaTestinterface () {@ Override public String test (String name) {return "slim" + name;}}
The lambda expression simplifies the above anonymous implementation as follows
LumbdaTestinterface testLambdaService = (name)-> {return "slim" + name;}
The parentheses in front of the parameters are written directly, the multiple parameters are separated by commas (the type can be omitted), and the method is written directly in parentheses after the arrow. There is only one parameter, and parentheses can be left unwritten. If you don't wrap the line after the arrow, you can save curly braces and return.
three. This implementation doesn't even have a method name, so why can you implement the test method? This is mentioned in 1, and this writing requires that the class can only have one abstract method, so this writing is the method to be implemented by default.
On how to use lambda expressions in java8 to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.