Re: A list of ever member in a class.



zero wrote:
Daniel Gee <zefria@xxxxxxxxx> wrote in news:1177371058.868913.54070
@n76g2000hsh.googlegroups.com:

this.elementData = (E[])new Object[initialCapacity];

Yes. Here they are creating an array of Objects, and casting it to an array of Es, which to the compiler is quite different from creating an array of Es directly.

If the people implementing ArrayList have to resort to this kind of tricks, maybe it should've made them wonder at the validity of generics.

It is not necessary to do this sort of cast in order to implement ArrayList. It's just to avoid lots of unchecked casts whenever an element is read from the array.

Anyway, now that ArrayList has been implemented, we can all use List instead of reference arrays. Even if ArrayList were implemented natively, the implementation still would not make any difference to other code.

Tom Hawtin
.