Govt Exams
Type erasure removes all generic type parameters during compilation. For unbounded types, they're replaced with Object; for bounded types, they're replaced with the upper bound.
Valid generic class declarations allow multiple type parameters with upper bounds. Option A is syntactically correct. Option C uses invalid 'super' keyword in class declaration. Option D has malformed syntax.
Generics provide compile-time safety, code reusability through parameterization, and clearer API contracts. These are essential for modern Java development standards.
Both A and C define valid generic methods with multiple type parameters. C is more explicit with 'public' modifier, but both are functionally equivalent.
List strings = new ArrayList();
List list = strings;
list.add(123);
String str = strings.get(0);
System.out.println(str);
Adding Integer 123 to raw type reference bypasses generics. When retrieving as String, a ClassCastException occurs at runtime.
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).