Govt Exams
Lower-bounded wildcards (? super T) allow superclasses of T. This assignment is valid because ArrayList<Number> fits '? super Integer'.
Upper-bounded wildcards (? extends T) are used for reading data. Adding elements is unsafe because the compiler doesn't know the exact type.
Option A uses proper diamond syntax with matching type parameters on both sides. Options B, C produce unchecked warnings, and Option D is invalid due to invariance.
List list = new ArrayList();
list.add(10);
Object obj = list.get(0);
System.out.println(obj instanceof Integer);
The Integer value is stored in the list. At runtime, type erasure converts it to Object, but the actual stored value remains an Integer instance.
interface Comparable { int compareTo(T o); }
Which class definition correctly implements this?
Option A correctly implements the generic interface by specifying the concrete type parameter as MyClass in the implements clause.
List<?> accepts any type but is read-only (can't add). List<Object> explicitly accepts Object type and allows adding objects.
Bounded type parameters restrict the types that can be used as arguments. T extends Number ensures T is Number or its subclass.
List
Upper bounded wildcards (? extends Number) are read-only. You cannot add elements because the compiler doesn't know the exact subtype.
List[] array = new List[10];
You cannot create arrays of generic types because of type erasure. The compiler prevents this with a compilation error.
Wildcards (?) represent an unknown type. Upper bound (? extends T) accepts T or its subtypes. Lower bound (? super T) accepts T or its supertypes.