Order by before where (ARCH4076)
Esta página aún no está disponible en tu idioma.
Key java.performance.orderby-before-where · Severity warning · Category performance
Sorting before filtering also sorts elements that will be discarded. Filter first to shrink the set that has to be sorted.
Incorrect
Section titled “Incorrect”return orders.stream() .sorted(comparing(Order::getDate)) .filter(Order::isActive) .collect(toList());Correct
Section titled “Correct”return orders.stream() .filter(Order::isActive) .sorted(comparing(Order::getDate)) .collect(toList());Move the sort after the filter so only the needed elements are sorted.