Bbpzz / min3d

Automatically exported from code.google.com/p/min3d
0 stars 0 forks source link

Not an issue per-se but an answer to a question left in source code comments... #38

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
In file min3d.core.TextureList#getIds(), there is a commented question:

  // BTW this makes a casting error. Why?
  // (TextureVo[])_t.toArray();

The answer is because the ArrayList _t does not know it contains TextureVo 
objects so toArray() returns Object[], and Object[] cannot be cast to 
TextureVo[].

Even though _t was declared as ArrayList<TextureVo>, the parameterized value of 
TextureVo is removed at compile-time through a process called erasure.  There 
is much debate over whether or not erasure was the right decision by Sun but 
we've got what we've got...

To correctly get the TextureVo[] from _t, use:

    TextureVo[] aTexturVo = _t.toArray(new TextureVo[_t.size()]);

You don't even have to cast it.

Original issue reported on code.google.com by tim.robi...@gmail.com on 22 Mar 2011 at 6:32