← 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?
- A.List<Integer> list = new ArrayList<>();
- B.static <T> void show(T x)
- C.T obj = new T(); inside a generic class
- 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 →