【发布时间】:2019-07-09 20:20:24
【问题描述】:
之前已经回答了类似的问题,但我仍然无法弄清楚我的分组和平均方法有什么问题。
我尝试了多个返回值组合,例如Map<Long, Double>、Map<Long, List<Double>、Map<Long, Map<Long, Double>>、Map<Long, Map<Long, List<Double>>>,但这些都不能解决 IntelliJ 向我抛出的错误:'Non-static method cannot be referenced from a static context '。
此刻我觉得我只是在盲目地猜测。那么谁能给我一些关于如何确定正确返回类型的见解?谢谢!
方法:
public static <T> Map<Long, Double> findAverageInEpochGroup(List<Answer> values, ToIntFunction<? super T> fn) {
return values.stream()
.collect(Collectors.groupingBy(Answer::getCreation_date, Collectors.averagingInt(fn)));
}
答题类:
@Getter
@Setter
@Builder
public class Answer {
private int view_count;
private int answer_count;
private int score;
private long creation_date;
}
【问题讨论】:
标签: java java-stream collectors