In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to deeply understand java1.8 and know supplier. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Supplier is also used to create objects, but unlike the traditional syntax for creating objects: new, see the following code:
Public class TestSupplier {private int age
TestSupplier () {System.out.println (age)
} public static void main (String [] args) {
/ / create a Supplier container, declared as TestSupplier, and the object constructor will not be called, that is, the object Supplier sup= TestSupplier::new will not be created.
System.out.println ("-")
/ / when the get () method is called, the constructor of the object is called, and the real object sup.get () is obtained.
/ / each time get calls the constructor, that is, the object obtained is different sup.get ()
}}
Output result:
-00
Official code and comments:
/ * Represents a supplier of results. *
*
There is no requirement that a new or distinct result be returned each * time the supplier is invoked. *
*
This is a functional interface *
Whose functional method is {@ link # get ()}.
* * @ param the type of results supplied by this supplier
* * @ since 1.8 * / @ FunctionalInterfacepublic interface Supplier {
/ * Gets a result. *
* @ return a result * / T get ()
}
According to the code and official comments, my personal understanding is:
1.supplier is an interface with a get () method
two。 Syntax:
Supplier sup= TestSupplier::new
3. Each time the get () method is called, the constructor is called to create a new object.
The above content is how to deeply understand java1.8 and know supplier. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are 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.
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.