Reusable Bounded Collector API
Challenge on lesson: Checkpoint: Generics & PECS
CHALLENGE
Difficulty: intermediate+25 XP
Build a small generic API inside Solution:
- static <T extends Comparable<T>> List<T> topN(List<T> xs, int n) โ
the n largest elements in DESCENDING order; n larger than size returns
all; n <= 0 throws IllegalArgumentException; xs null/empty throws too.
- static double sumNumbers(List<? extends Number> xs) โ PECS producer.
- static <T> List<? super T> drain(List<T> src, List<? super T> dst) โ
moves every element from src into dst and returns dst; src ends empty.
All three signatures must keep the generic promises above (the tests
compile call sites that would fail with weaker types).
Press Submit to check your solution.
Back to lesson: Checkpoint: Generics & PECS