Govt Exams
Java uses ampersand (&) to combine multiple bounds. The class must appear first, followed by interfaces. Commas, pipes, and 'implements' keyword are not valid syntax for type parameter bounds.
'? extends TargetClass' creates a covariant wildcard allowing lists of TargetClass or any subclass. This is ideal for reading operations when you need polymorphic list handling.
Option A uses single type parameter T for entity type, which is the standard pattern for generic repositories. Option C is redundant (all classes extend Object), and Option D adds unnecessary complexity.
Using 'T extends Number' establishes an upper bound, allowing the method to work with any Number subclass (Integer, Double, Float, etc.) while providing type safety and access to Number methods.
java
List list = new ArrayList();
Class c = list.getClass();
Due to type erasure, getClass() returns ArrayList without generic parameters. Generic information exists only at compile time.
Bridge methods are synthetic methods generated during compilation to maintain polymorphism with generic types and type erasure.
java
List
With lower-bounded wildcard (? super Integer), you can add Integer but retrieval returns Object. Casting Object to Integer without proper type causes ClassCastException.
You cannot create arrays of generic types due to type erasure and heap pollution risks. Use Collection framework instead of arrays.
public T findMin(T[] arr)
Type erasure replaces T with its bound Comparable. The method signature becomes public Comparable findMin(Comparable[] arr).
List<Object> accepts Object and its subclasses for adding. List<?> (unbounded wildcard) is more flexible for reading but restrictive for writing (only null).