Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error on token "::", invalid AssignmentOperator when groupingBy

I have this class:

public class MenuPrice {


    private BigDecimal price;


    private Date updateDate;


}

I want to group by Date,

List<MenuPrice> menuPrices = findAll(restaurant);

menuPrices
                .parallelStream()
                .collect(Collectors.groupingBy(MenuPrice::getUpdateDate()));

but I have a compilation error : Syntax error on token "::", invalid AssignmentOperator

like image 426
Nunyet de Can Calçada Avatar asked Dec 06 '25 07:12

Nunyet de Can Calçada


1 Answers

This is a simple syntax problem you are having here:

.collect(Collectors.groupingBy(MenuPrice::getUpdateDate));

But, I've seen that in other questions you (ab)use parallel in streams. This is most probably never a good idea, as you usually require lots of data for parallel to have any relevance.

Than using java.util.Date raises questions too; it's a really old API... This is especially weird since you use java-8 for streaming, but it already comes with far better classes in the java.time package

like image 106
Eugene Avatar answered Dec 08 '25 16:12

Eugene



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!