What is the relationship between raw types and generics in Java?
Q.362Medium
Consider the method: public static <T> T getFirst(List<T> list) { return list.get(0); }
How would you call this method for a List<String>?
Q.363Medium
What is the significance of the '&' operator in generic bounds like '<T extends A & B>'?
Q.364Medium
Which statement about generic type parameters is TRUE?
Q.365Medium
Consider the declaration: List<? super Integer> list. What does this wildcard represent?
Advertisement
Q.366Medium
Which statement correctly defines a generic class with multiple type parameters and bounds?
Q.367Medium
Consider: public static <T> T findMax(T a, T b) { return a; }. What is the issue with calling findMax(5, 3.5)?
Q.368Medium
What does List<?> represent in Java generics?
Q.369Medium
Which of the following will NOT compile?
Q.370Medium
Consider a generic interface: interface Comparable<T> { int compareTo(T obj); }. How should a class implement this for String comparison?
Q.371Medium
What happens when you use raw type List instead of List<String>?
Q.372Medium
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.373Medium
How would you define a generic method that works with a pair of objects and returns the first one?
Q.374Medium
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.375Medium
Which of the following will cause a compile-time error?
Q.376Medium
What does the following generic method signature indicate?
public static <T extends Comparable<T>> T findMax(T[] array)
Q.377Medium
Given: Map<String, ? extends List<?>> map = new HashMap<>();
Which operation is valid?
Q.378Medium
What is the output of this code?
List<String> strings = new ArrayList<>();
List raw = strings;
raw.add(123);
String str = strings.get(0);
Q.379Medium
Consider:
public class Pair<T, U> { }
Which declaration is invalid?
Q.380Medium
What is the correct way to declare a generic method that accepts a list and returns the maximum element?