Consider the code:
java
List<Number> list = new ArrayList<Integer>();
Will this compile?
Q.82Medium
What is the correct output of this code?
java
List<? extends Number> list = new ArrayList<Integer>();
list.add(5);
Q.83Medium
Which wildcard usage follows the Producer pattern?
Q.84Medium
What does 'covariance' mean in the context of Java Generics?
Q.85Medium
What is the PECS principle in Java Generics?
Advertisement
Q.86Medium
Which of these is a valid generic interface implementation?
Q.87Hard
What will happen when you compile and run this code?
java
List<String> strings = Arrays.asList("a", "b", "c");
List raw = strings;
raw.add(123);
String s = strings.get(3);
Q.88Hard
Consider this declaration: public static <T> List<T> createList(). Which statement about type inference is correct?
Q.89Hard
What is the difference between List<Object> and List<?> in practical usage?
Q.90Hard
What is the compiled bytecode signature of this generic method?
public <T extends Comparable<T>> T findMin(T[] arr)
Q.91Hard
Which statement about generic array creation is correct?
Q.92Hard
What output will this produce?
java
List<? super Integer> list = new ArrayList<Number>();
list.add(5);
Integer val = (Integer) list.get(0);
Q.93Hard
Which Java feature was introduced specifically to support generics compilation?
Q.94Medium
What is the runtime class object for this generic variable?
java
List<String> list = new ArrayList<String>();
Class<?> c = list.getClass();
Q.95Medium
A developer creates a generic method that accepts a collection of numbers and calculates their sum. Which type parameter declaration would be most appropriate for this scenario?
Q.96Easy
In a Spring Boot application, you need to create a generic repository interface that works with any entity type. Which declaration correctly implements this pattern?
Q.97Medium
A utility class needs a method that accepts a List containing elements that are instances of a specific class or its subclasses. Which wildcard notation should be used?
Q.98Easy
When using bounded type parameters with multiple interfaces, what is the correct syntax in Java?
Q.99Hard
A method processes collections where items need to be added back to the same collection type. Which wildcard approach ensures type safety for write operations?
Q.100Medium
In a microservices architecture, you're designing a Response wrapper class that should work with any data type, including primitives when boxed. Which implementation is correct?