Use gatherers for custom intermediate stream operations.
Porównanie kodu
✕ Java 8
// Sliding window: manual implementation
List<List<T>> windows = new ArrayList<>();
for (int i = 0; i <= list.size()-3; i++) {
windows.add(
list.subList(i, i + 3));
}
✓ Java 24+
var windows = stream
.gather(
Gatherers.windowSliding(3)
)
.toList();
Widzisz problem z tym kodem? Daj nam znać.
Dlaczego nowoczesne podejście wygrywa
Composable
Gatherers compose with other stream operations.
Built-in operations
windowFixed, windowSliding, fold, scan out of the box.
Extensible
Write custom gatherers for any intermediate transformation.
Stare podejście
Custom Collector
Nowoczesne podejście
gather()
Od JDK
24
Poziom trudności
Zaawansowany
Wsparcie JDK
Stream gatherers
Dostępne
Finalized in JDK 24 (JEP 485, March 2025).
Jak to działa
Gatherers are a new intermediate stream operation that can express complex transformations like sliding windows, fixed-size groups, and scan operations that were impossible with standard stream ops.
Powiązana dokumentacja