What happens inside Java\'s ArrayList
(and probably many other classes) is that there is an internal Object[] array = new Object[n];
, to w
I think is more a matter of code style not of performance or type safety (because the backing array is private)
The java 5 ArrayList was implemented the way you suggested with an E[]
array. If you look at the source code you see that it contains 7 (E[]) casts. From java 6 the ArrayList changed to use an Object[]
array which resulted in only 3 (E) casts.