Reputation: 1717
I have this list that I want to order in reserve order, but I didn't find any .reversed()
function in autocomplete assist
myMenus(user)
.stream()
.filter(mps -> mps.get1PercentageChange() > 0 &&
mps.get2PercentageChange() > 0 &&
mps.get3PercentageChange() > 0 &
mps.get4PercentageChange() > 0)
.sorted(comparing(mps -> mps.getDailyPercentageChange()))
.collect(toList());
I have also tried:
myMenus(user)
.stream()
.filter(mps -> mps.get1PercentageChange() > 0 &&
mps.get2PercentageChange() > 0 &&
mps.get3PercentageChange() > 0 &
mps.get4PercentageChange() > 0)
.sorted(comparing(mps -> mps.getDailyPercentageChange()).reversed())
.collect(toList());
but then I have the compilation error:
Cannot infer type argument(s) for <T, U> comparing(Function<? super T,?
extends U>)
Upvotes: 6
Views: 11277
Reputation: 56433
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.
Upvotes: 8
Reputation: 36401
Comparator
s have a reversed
method to get the reverse ordering, so :
.sorted(comparing(mps -> mps.getDailyPercentageChange()).reversed())
should work.
Upvotes: 5