Type a method that reads from a wildcard-bounded list
Type a method that reads from a wildcard-bounded list
Answer
public static double sum(List<? extends Number> list) { double total = 0; for (Number n : list) total += n.doubleValue(); return total; }
? extends Number — the list is a producer of Numbers. You read elements as Number but cannot add to it.