Grokking Java Interview Questions
Vote

0% completed

​

Limits of Generics

Each item below is ordinary code with a type parameter or a type argument in it, and javac rejects all of them:

  • The expression new T() gives the message unexpected type.
  • The expression new T[10] gives generic array creation.
  • The type List<int> gives unexpected type.
  • The class Problem<T> extends RuntimeException gives a generic class may not extend java.lang.Throwable.
  • The methods print(List<String>) and print(List<Integer>) in one class have the same erasure.

All five have one cause, which is type erasure

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content