Hi. I have a little problem with my code. I want to cast a complete arrayList to a different type, but java wont let me... Here is a compressed version of what is happening:
//The interface I use.
public abstract interface Drawable{
//some methods
}
//A class that is supposed to be drawable
public abstract class pObject implements Drawable{
//Methods
}
//A class that works magic on the objects
public class engine{
ArrayList<pObject> obs = new...;
//Method returning the pObjecs, that is drawable
public ArrayList<pObject> getList(){
return obs;
}
}
//The rendering work horse
public class drawer{
arrayList<Drawable> draw = new...;
//The method that should add drawable objects to the rendering stack
public void addArrayList(ArrayList<Drawable> i)
{
draw.addAll(i);
}
}
//A random class that binds everything together
public class someThing{
engine en = new ...;
drawer drawer1 = new..;
public void addObjects(){
//Finally, here is the issue: I get error saying the list is not able to be cast
// to a drawable type
drawer1.addObjects((ArrayList<Drawable>)en.getList());
}
}
Soooo.. What is the issue here? Is it simply syntax or something else?