Govt. Exams
Entrance Exams
While convention uses single uppercase letters, type parameters can be any valid identifier. Statements B and D are also incorrect.
Multiple bounds (using &) mean T must satisfy all constraints. This is useful when a type needs to implement multiple interfaces.
How would you call this method for a List?
Type inference in Java allows the compiler to deduce T from the argument type, so both explicit and implicit type specification work.
Raw types (like 'List' without type parameters) are legacy and should be avoided as they bypass compile-time type safety.
Nested wildcards like '? extends ? super T' are not allowed. Wildcards cannot be combined or nested.
The bound 'T extends Comparable<T>' ensures T is comparable to itself, enabling type-safe comparison operations.
PECS guides when to use upper bounds (? extends) for producers/readers and lower bounds (? super) for consumers/writers.
All three allow storing multiple types because they use unbounded or Object-level wildcards, though List<?> is most restrictive for additions.
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.