Circular reasoning Java lambda grouping
•
Java
I am familiar with Lambdas and confused with the error I made in this line of code:
HashMap<Date,ArrayList<Trade>> groupTrades = allTrades.stream().collect(Collectors.groupingBy(Trade::getTradeDate()));
IntelliJ does not compile for loop inference
Solution
After a lot of pain, I have completed all this. I hope it is also useful to others
You can't use HashMap or ArrayList - as long as you use the interface map and list, the code should be:
Map<Date,List<Trade>> groupTrades = allTrades.stream().collect(Collectors.groupingBy(Trade::getTradeDate));
Please note that when any parameter in groupby does not match the expectation in the declaration of map, it may lead to a fairly general message
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码