~/ learn/ comp-308/ cards/ Wildcards: ? extends / ? super (PECS)
1 of 5

Type a producer parameter (? extends) and read it

Type a producer parameter (? extends) and read it

Answer

static double sum(List<? extends Number> list) { double total = 0; for (Number n : list) total += n.doubleValue(); return total; }

? extends Number is an upper-bounded wildcard: each element is at least a Number, so reading as Number is safe. You may NOT add to such a list — the exact element type is unknown. This is the producer side of PECS.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/27f5163f-390e-4c37-893d-a9e195435bba/flashcard utf-8 LF