gpt4 book ai didi

java - Stream.reduce(Float,BinaryOperator) BinaryOperator 指的是哪个功能接口(interface)方法?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:14:55 26 4
gpt4 key购买 nike

例如,

List<Product> productsList = new ArrayList<Product>();  
productsList.add(new Product(1,"HP Laptop",25000f));
productsList.add(new Product(2,"Dell Laptop",30000f));
productsList.add(new Product(3,"Lenevo Laptop",28000f));
productsList.add(new Product(4,"Sony Laptop",28000f));
productsList.add(new Product(5,"Apple Laptop",90000f));

Float totalPrice = productsList.stream()
.map(product->product.price)
.reduce(0.0f,(sum, price)->sum+price);
System.out.println(totalPrice);

这里(sum, price)->sum+price指的是哪个功能接口(interface)?

最佳答案

因为你提到了“功能接口(interface)方法”:reduce实际上是在调用 apply of BiFunction (BinaryOperator 从中延伸)。

关于java - Stream.reduce(Float,BinaryOperator) BinaryOperator 指的是哪个功能接口(interface)方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54437390/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com