🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.So the method can call compareTo on T values
  2. B.So T can be a primitive
  3. C.So the method can create new T objects
  4. 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 →