lundi 18 juin 2018

Creating class instances stored in a list

So first I make an ArrayList. (? means that I don't know what should be there, keep reading)

ArrayList<?> arrayList = new ArrayList<?>();

So this will store class name of abstract class Class, so for example it might stores ExtendedClass1 or ClassExtended2.

Later I iterate through that ArrayList and create new objects with the name stored in arraylist

for (int i = 0; i < arrayList.size(); i++) {
    new arrayList.get(i); // Takes the class name and makes new object out of it
}

How can I actually do it?





Aucun commentaire:

Enregistrer un commentaire