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
.



Relevant Pages

  • Re: array of lists
    ... That is a measure of last resort. ... If the compiler is making a noise, ... create an array WITH a generic type then it ... A warning is exactly that, ...
    (comp.lang.java.programmer)
  • Re: Idea for ECMA/C# Standard - compile time hash for performance
    ... I agree with you the chance of a compiler change is slim, ... and then delegating to the standard hash for fields accessed less frequently. ... or the array lookup which would require the ... > 64-bit architecture) for each enum value that doesn't map to anything. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Q: Checking the size of a non-allocated array?
    ... an actual argument is already invalid ... First note that you don't have an unallocated array in the subroutine. ... it is comparable to disassociated or undefined pointers. ... Obviously the compiler has ...
    (comp.lang.fortran)
  • Re: Windows array allocation problem
    ... array reference has to have a 64-bit index or array subscript triplet? ... to fit in one. ... That assumes, of course, that your compiler ... limits on just about anything. ...
    (comp.lang.fortran)
  • Re: Is this expected behavior or not
    ... This gives you array interfaces while keeping arrays ... to know the representation in order to be able to pass it meaningfully. ... not a normal array if you are using the character interface). ... should have a tag and it's up to the compiler how to implement it. ...
    (comp.lang.ada)