Grokking Java Interview Questions
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 messageunexpected type. - The expression
new T[10]givesgeneric array creation. - The type
List<int>givesunexpected type. - The class
Problem<T> extends RuntimeExceptiongivesa generic class may not extend java.lang.Throwable. - The methods
print(List<String>)andprint(List<Integer>)in one classhave the same erasure.
All five have one cause, which is type erasure
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%