ProgrammingVery hardGATE CS · TCS NQT Prime · Product Company SDE

What does `List<? super Integer>` allow, in contrast to `List<? extends Integer>`?

  1. A. Safely inserting Integer (or its subtypes) into the list, while reading elements back out is only guaranteed to be Object (since the exact supertype is unknown)
  2. B. Behaving identically to an unparameterised raw List
  3. C. Neither reading from nor writing to the list at all
  4. D. Reading elements out safely as Integer while also inserting freely, with full type safety both ways

Correct answer: A. Safely inserting Integer (or its subtypes) into the list, while reading elements back out is only guaranteed to be Object (since the exact supertype is unknown)

A lower-bounded wildcard guarantees the list's element type is Integer or some supertype of it, so inserting an Integer is always safe, but reading only guarantees an Object back.

More OOP with C++ and Java questions

Exams that ask this topic