In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to understand Java12 Collectors.teeing, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Preface
There is a very useful feature in Java 12 that is not announced in the official JEP, because it is just a small change in Collector. It works as a result of two collector in merge. This sentence is very abstract. Let's take a look at the picture first:
This little thing is often used in pipeline reconstruction. We usually call it the "three links". Its main function is to merge the inflows of downstream1 and downstream2, and then flow out of merger.
With the description of this image, let's get down to business.
Collectors.teeing
The small function mentioned above is Collectors.teeing API. First, let's take a look at JDK's description of the API. Just ignore it if you feel uncomfortable, and then go on to look at the example:
/ * Returns a {@ code Collector} that is a composite of two downstream collectors. * Every element passed to the resulting collector is processed by both downstream * collectors, then their results are merged using the specified merge function * into the final result. * *
The resulting collector functions do the following: * * supplier: creates a result container that contains result containers * obtained by calling each collector's supplier * accumulator: calls each collector's accumulator with its result container * and the input element * combiner: calls each collector's combiner with two result containers * finisher: calls each collector's finisher with its result container, * then calls the supplied merger and returns its result. * * *
The resulting collector is {@ link Collector.Characteristics#UNORDERED} if both downstream * collectors are unordered and {@ link Collector.Characteristics#CONCURRENT} if both downstream * collectors are concurrent. * * @ param the type of the input elements * @ param the result type of the first collector * @ param the result type of the second collector * @ param the final result type * @ param downstream1 the first downstream collector * @ param downstream2 the second downstream collector * @ param merger the function which merges two results into the single one * @ return a {@ code Collector} which aggregates the results of two supplied collectors. * @ since 12 * / public static Collector teeing (Collector
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: 214
*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.