[SOLVED] (ZetCode Tutorial) someone explain this line please

Hello,
am following this tutorial
http://zetcode.com/tutorials/javagamestutorial/collision/
and i didn’t understand the need of this line in the Board class
(ctrl+f to find it easily )

Missile m = (Missile) ms.get(i);

and this

Alien a = (Alien) aliens.get(i);

i know that the variables “m” and “a” are the temporary missile and alien inside the loops, but why the casting ?
(Missile) ms.get(i) ??

i really don’t know why i had to cast

thank you

When defining the ArrayList, they don’t use generics, so the compiler doesn’t know what type the objects pulled out of the arraylist will be.

To avoid casting, define the ArrayList like this:


ArrayList<Missile> missiles = new ArrayList<Missile>();

etc.

Thank you ;D