Java 8 Lambda: Comparator

前端 未结 7 1562
鱼传尺愫
鱼传尺愫 2021-02-01 12:53

I want to sort a list with Lambda:

List messagesByDeviceType = new ArrayList();      
messagesByDeviceType.sort((Message o1, Messag         


        
7条回答
  •  不要未来只要你来
    2021-02-01 13:31

    The Comparator's compare() method must return an int, and it seems yours is returning a long.

    You can change it to:

    (Message o1, Message o2)->Long.compare(o1.getTime(),o2.getTime())
    

    This is assuming (based on your error message) that o1.getTime() returns a long.

提交回复
热议问题