What is the primary advantage of using generics in Java?
Q.22Medium
In the declaration 'List<? extends Number> list', what types can be added to this list at runtime?
Q.23Medium
Which statement correctly uses the lower-bounded wildcard in generics?
Q.24Medium
Which generic declaration would allow storing both String and Integer in the same collection?
Q.25Medium
What does the PECS principle stand for in generics context?
Advertisement
Q.26Easy
Which of the following will compile successfully?
Q.27Medium
In a generic class 'class Box<T extends Comparable<T>>', what constraint is placed on T?
Q.28Easy
What is the output of this code snippet?
ArrayList<String> list = new ArrayList<>();
list.add("Java");
Object obj = list.get(0);
String str = (String) obj;
System.out.println(str.length());
Q.29Medium
Which generic wildcard usage is INCORRECT?
Q.30Medium
What is the relationship between raw types and generics in Java?
Q.31Medium
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.32Hard
What will happen when you try to create an array of generic types like 'new ArrayList<String>[10]'?
Q.33Easy
In the interface declaration 'interface Pair<K, V>', how many type parameters does it have?
Q.34Medium
What is the significance of the '&' operator in generic bounds like '<T extends A & B>'?
Q.35Hard
Consider: Map<String, ? extends List<?>> map = new HashMap<>();
What can you safely retrieve from this map?
Q.36Medium
Which statement about generic type parameters is TRUE?
Q.37Hard
What is the key difference between '? extends T' and '? super T' in practical usage?
Q.38Easy
Which of the following is a valid generic method declaration in Java?
Q.39Easy
What is the primary purpose of bounded type parameters in generics?
Q.40Medium
Consider the declaration: List<? super Integer> list. What does this wildcard represent?