← Quiz: Java Generics: all 10 questions
Quiz: Java Generics · Question 5 of 10
In static <T extends Comparable<T T max(List<T list), why is the bound needed?
In static <T extends Comparable<T>> T max(List<T> list), why is the bound needed?
- A.So the method can call compareTo on T values
- B.So T can be a primitive
- C.So the method can create new T objects
- D.It is not needed; it only documents the code
Answer & explanation
Correct answer: So the method can call compareTo on T values
Without the bound, T is just an Object and has no compareTo method.
Can you get the rest right without peeking?
Take the timed Quiz: Java Generics quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →