Govt. Exams
Entrance Exams
public void sort(T[] array)
With multiple bounds using '&', type erasure replaces T with the first bound. Here, Number is the first bound, so T is replaced with Number.
Consumer pattern uses '? super T' (lower bound). This allows adding elements safely. Option A (producer pattern) only allows reading, and Options C and D restrict type flexibility.
Cannot instantiate generic type T directly. Using Class<T>.newInstance() is a valid pattern (though deprecated in newer Java versions in favor of getConstructor()). Option A is invalid.
Generic constructors can exist in non-generic classes. Constructor's type parameters are separate from and independent of the class's type parameters.
PECS (Producer Extends, Consumer Super) is a mnemonic for wildcard bounds: use '? extends' when reading (producing), use '? super' when writing (consuming).
Due to type erasure, T is replaced with Object at runtime, and you cannot instantiate Object with new T(). You need reflection or pass Class<T> as parameter.
<T extends Comparable<T>> is a recursive bound ensuring T implements Comparable of its own type. <T extends Comparable> uses raw type, losing type information.
All three approaches allow processing lists of any type, though they differ: raw type (unsafe), unbounded wildcard (read-only), and type parameter (flexible).
Upper bounds (? extends T) are safe for reading because the compiler knows it's at least T. Lower bounds (? super T) are safe for writing because you can pass T or any superclass.
The value type is '? extends List<?>', so you get a List with unknown element type. The exact subtype is unknown at compile-time.