I have a simple class structure:
class BaseModel {}
class Performer extends BaseModel {}
And I have a collection of Performers:
ArrayList<Performer> list = loadPerformerList();
Why can’t I do this?
functionThatNeedsArrayOfBase( (ArrayList<BaseModel>)list );
Or, how can I do that, properly?
A collection of child is not a collection of base. Otherwise you could add base objects to your child collection, breaking the assumption (same the other way around as well).
You could specify the parameter to your function as a list containing derivatives of base:
Then you can just pass
listwithout casting