Java 8 Lambda: Comparator

前端 未结 7 1447
鱼传尺愫
鱼传尺愫 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:24

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

    You can change it this into:

    Long.compare(o1.getTime(),o2.getTime())
    

    Well explained regarding lambda comparator in the below presented video link.

提交回复
热议问题