Java8 lambda: sort a stream in reverse order?
It's a type inference issue. You'll need to help the compiler out.
few things you could try:
.sorted(comparing(T::getDailyPercentageChange).reversed())
or
.sorted(comparing((T mps) -> mps.getDailyPercentageChange()).reversed())
Where T
is the type of elements being compared.
Comparator
s have a reversed
method to get the reverse ordering, so :
.sorted(comparing(mps -> mps.getDailyPercentageChange()).reversed())
should work.