Consider the code:
java
List<Number> list = new ArrayList<Integer>();
Will this compile?
Q.782Medium
What is the correct output of this code?
java
List<? extends Number> list = new ArrayList<Integer>();
list.add(5);
Q.783Medium
Which wildcard usage follows the Producer pattern?
Q.784Medium
What does 'covariance' mean in the context of Java Generics?
Q.785Medium
What is the PECS principle in Java Generics?
Advertisement
Q.786Medium
Which of these is a valid generic interface implementation?
Q.787Hard
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.788Hard
Consider this declaration: public static <T> List<T> createList(). Which statement about type inference is correct?
Q.789Hard
What is the difference between List<Object> and List<?> in practical usage?
Q.790Hard
What is the compiled bytecode signature of this generic method?
public <T extends Comparable<T>> T findMin(T[] arr)
Q.791Hard
Which statement about generic array creation is correct?
Q.792Hard
What output will this produce?
java
List<? super Integer> list = new ArrayList<Number>();
list.add(5);
Integer val = (Integer) list.get(0);
Q.793Hard
Which Java feature was introduced specifically to support generics compilation?
Q.794Medium
What is the runtime class object for this generic variable?
java
List<String> list = new ArrayList<String>();
Class<?> c = list.getClass();
Q.795Medium
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.796Easy
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.797Medium
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.798Easy
When using bounded type parameters with multiple interfaces, what is the correct syntax in Java?
Q.799Hard
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.800Medium
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?