Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please explain this statement from Java Generics FAQ

Tags:

java

generics

Can someone please explain what is meant by the following statement :

Creation of arrays with a non-reifiable component type is not permitted.

This is written in Anjelika Langer's Java Generics FAQ

like image 425
Geek Avatar asked Oct 09 '12 12:10

Geek


1 Answers

Creation of arrays with a non-reifiable component type is not permitted.

in practice means that generic array creation is illegal:

new T[...] // prohibited

Generic arrays are not allowed, because arrays contain information about its component at runtime. This is not true for generics. Generics are implemented at compiler level. Hence, the component type must be known beforehand when the array is created.

like image 193
Konrad Reiche Avatar answered Oct 10 '22 07:10

Konrad Reiche