~/ 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/eabad171-bb7f-413b-adea-a37b1c7bd213/flashcard utf-8 LF