🎙 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 7 of 10

Which of these is NOT allowed because of type erasure?

Which of these is NOT allowed because of type erasure?

  1. A.List<Integer> list = new ArrayList<>();
  2. B.static <T> void show(T x)
  3. C.T obj = new T(); inside a generic class
  4. D.class Box<T extends Number>
Answer & explanation

Correct answer: T obj = new T(); inside a generic class

At runtime the type T is unknown, so the JVM cannot create a T object.

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 →