Arraylist of subclass
Dear all,
I have a class called Gene that have two subclasses : Translation and RotationAngle
chromozome is an ArrayList<Gene>
I add in Chromozome instances of Translation and RotationAngle :
ArrayList<Gene> chromozome =new ArrayList<Gene>();
chromozome.add(new Translation());
chromozome.add(new Translation());
chromozome.add(new RotationAngle());
I want then to access them :
Translation t1 = (Translation)chromozome.get(0);
Translation t2 = (Translation)chromozome.get(1);
RotationAngle ra = (RotationAngle)chromozome.get(2);
The last line throws a ClassCastException saying Translation can not be cast to RotationAngle ...
I truly do not get it, since this part of the ArrayList always contained instance of RotationAngle !!!
Is this normal ?
thx,
Vincent

