What will be the result of executing: List<Integer> list = new ArrayList<String>();
Q.742Medium
Which statement correctly defines a generic class with multiple type parameters and bounds?
Q.743Medium
Consider: public static <T> T findMax(T a, T b) { return a; }. What is the issue with calling findMax(5, 3.5)?
Q.744Medium
What does List<?> represent in Java generics?
Q.745Medium
Which of the following will NOT compile?
Advertisement
Q.746Easy
What is the output of the following code?
List<Integer> list = new ArrayList<Integer>();
list.add(10);
Object obj = list.get(0);
System.out.println(obj.getClass().getName());
Q.747Medium
Consider a generic interface: interface Comparable<T> { int compareTo(T obj); }. How should a class implement this for String comparison?
Q.748Medium
What happens when you use raw type List instead of List<String>?
Q.749Hard
Which generic declaration allows a method to accept List of any type?
Q.750Hard
What is the difference between <T extends Comparable<T>> and <T extends Comparable>?
Q.751Hard
Can you create an instance of generic type parameter directly like: T obj = new T();?
Q.752Hard
What is the PECS principle in generics?
Q.753Hard
Which statement about generic constructors is TRUE?
Q.754Medium
What is the output?
List<String> strings = new ArrayList<String>();
List list = strings;
list.add(123);
String str = strings.get(0);
System.out.println(str);
Q.755Medium
How would you define a generic method that works with a pair of objects and returns the first one?
Q.756Easy
What is the advantage of using generics over raw types in terms of 2024-25 Java standards?
Q.757Easy
Which of the following is a valid generic class declaration in Java?
Q.758Easy
What is the result of type erasure in Java generics?
Q.759Medium
Consider the following code snippet:
public <T> T processData(List<? extends T> list) { return list.get(0); }
What is the relationship between the wildcard and type parameter T?
Q.760Medium
Which of the following will cause a compile-time error?