Reputation: 23
Say I have one superclass, and several subclasses inheriting it. I'd like to cram all of them into the same Arraylist for easy interaction, because for this one specific interaction, im only messing with stuff they have in common from the superclass.
Is this doable, or will I absolutely need a separate Arraylist for each object type?
If it is, how?
If ArrayLists can't do this, are there any other operable collections that could?
Upvotes: 2
Views: 2658
Reputation: 28623
you can create the arraylist as
List<YourSuperClass> list = new ArrayList<YourSuperClass>();
Upvotes: 5