ProgrammingVery hardGATE CS · TCS NQT Prime · Product Company SDE
What does `List<? super Integer>` allow, in contrast to `List<? extends Integer>`?
- 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)
- B. Behaving identically to an unparameterised raw List
- C. Neither reading from nor writing to the list at all
- 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
- java try { throw new ArithmeticException("x"); } catch (RuntimeException e) { System.out.print("R"); } catch (ArithmeticException e) {…
- Which OOP principle bundles data with the methods that act on it and hides the internal state behind an interface?
- In Java, which keyword makes one class inherit from another class?
- What is the return type of a C++ constructor?
- Every Java class that declares no superclass implicitly extends:
- In C++, members of a class declared without any access specifier are: