New constructor in xxxsummarystatistics java-10
I see that java-10 adds a constructor for intsummarystatistics (long summarystatistics and double summarystatistics), which accepts four parameters, namely count, min, Max and sum
I understand why the no args constructor exists, so it will be used for simplification, such as:
..stream().collect(Collectors.summarizingInt(Class::someFunction))
This makes sense, but why add a constructor with four parameters? I made a hypothesis in my answer, but if not, I'd be happy to take it back
Solution
Note that although this optimization did not occur in the reference implementation today, it is like intstream rangeClosed(from,to). Operations such as summarystatistics () do not need to actually iterate over all values
It can simply return the new intsummarystatistics ((long) to from 1, from, to, ((long) from to) * ((long) to from 1) / 2)
As mentioned above, this optimization will not happen today, but there is an example. Sometimes, there are some methods to calculate such statistics without iterating each value. Therefore, the only way to fill xxxsummarystatistics is to accept a single value (and combination, but this requires an existing statistical instance that must be filled in some way)