Update: My classes are more complex than this, I just am stuck on the ArrayList line
I have the following classes:
class CatList {
List<Cat> cats = new ArrayList<Cat>();
}
and
class DogList {
List<Dog> dogs = new ArrayList<Dog>();
}
Where Cat and dog are both data classes.
but I want to create an abstract class:
abstract class AnimalList {
List<???> animals;
AnimalList(Class animal) {
animals = new ArrayList<???>();
}
}
so that I can inherit my classes
AnimalList CatList = new AnimalList(Cat);
AnimalList DogList = new AnimalList(Dog);
AnimalList CowList = new AnimalList(Cow);
Hopefully that makes more sense. My question is therefore What are the ??? bits?
Using a type parameter might solve your problem – using the same class for different types – without inheritance:
Now you can parametize instances for persons and animals: