Govt Exams
Multiple type parameters with bounds must be comma-separated and each can have its own upper bound. Option C shows correct syntax with recursive bound on T and bound on K.
'? super Integer' is a lower bounded wildcard that accepts Integer and all its superclasses like Number, Object. This allows write operations with Integer values.
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.