看一下下面的代码:在二进制运算符中,我们有reduce((x,y)-> x + x)。为什么实际上计算为Optional [512]?我没有解释
System.out.println((Stream.generate(()->1d).limit(10).
peek((doubleValue)->{
System.out.println("Call the first peek: "+doubleValue);
}).
reduce((x,y)->x+x)));
Run Code Online (Sandbox Code Playgroud)
这是输出:为了向您澄清,我在peek部分中显示了各个x为1.0。
Call the first peek: 1.0
Call the first peek: 1.0
Call the first peek: 1.0
Call the first peek: 1.0
Call the first peek: 1.0
Call the first peek: 1.0
Call the first peek: 1.0
Call the first peek: 1.0
Call the first peek: 1.0
Call the first peek: 1.0
Optional[512.0]
Run Code Online (Sandbox Code Playgroud)
那么问题是,在获得Optional [512]之前,什么样的治理才能起作用?
因为您有10个参数,但运算为9。2 ^ 9 = 512
| 归档时间: |
|
| 查看次数: |
74 次 |
| 最近记录: |