Practice ยท 1 of 3
PECS: Sum Into and Out Of Lists
Implement two methods that demonstrate PECS signatures:
- static double sum(List<? extends Number> src) โ producer side,
returns the total as double.
- static void fill(List<? super Integer> dst, int a, int b, int c) โ
consumer side, appends a, b, c in order.
Then static List<Number> demo() returns a List<Number> produced by
calling fill on it and then sum over it โ proving one method reads a
List<Number> and the other writes into it, exactly as the wildcards
promise.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Generics Lab