我有一个客户对象列表(客户:int id,bool isActive,int billingCount,...)并且想要 billingCount 的总和和平均值。不幸的是,我的代码不起作用。我需要如何更改代码才能正常工作?
sum 和 average sould 看起来像这样:
真1234
假 1234
Map<Boolean, Integer> sum = customer.stream()
.map(c -> c.getIsActive())
.collect(Collectors.groupingBy(c -> c, Collectors.summingInt(Customer::getBillingCount)));
Map<Boolean, Integer> average = customer.stream()
.map(c -> c.getIsActive())
.collect(Collectors.groupingBy(c -> c, Collectors.averagingInt(Customer::getBillingCount)));
}
我收到以下错误:
Error:(146, 17) java: no suitable method found for collect(java.util.stream.Collector<Customer,capture#1 of ?,java.util.Map<java.lang.Object,java.lang.Integer>>)
method java.util.stream.Stream.<R>collect(java.util.function.Supplier<R>,java.util.function.BiConsumer<R,? super java.lang.Boolean>,java.util.function.BiConsumer<R,R>) is not applicable
(cannot infer type-variable(s) R
(actual and formal argument lists differ in length))
method java.util.stream.Stream.<R,A>collect(java.util.stream.Collector<? super java.lang.Boolean,A,R>) is not applicable
(inference variable T has incompatible bounds
lower bounds: java.lang.Object,Customer
lower bounds: java.lang.Boolean)
凤凰求蛊
ABOUTYOU
婷婷同学_
相关分类