So, Google had a lot of questions about getting a .classparameterized type, but I'm trying to go the other way.
I have a list of classes, and I need to create a map that uses Classas a key, and ArrayListobjects of type Class as a value. Something like that:
Class[] classes = getArrayOfClasses();
HashMap<Class, ArrayList<?>> map = new HashMap<Class, ArrayList<?>>();
for(Class c : classes) {
map.put(c, new ArrayList<c>());
}
The problem, of course, is that it needs a parameterized type, not a class. One possible solution is to simply use it map.put(c, new ArrayList<Object>()), but then I have to know the type and throw every object that I draw.
MyClass myObj = (MyClass) map.get(MyClass.class).get(0);
I also tried to make the initialization function as follows:
private <T> ArrayList<T> makeArrayList(Class<T> c) {
return new ArrayList<T>();
}
, , , , ArrayList of Object, .
, , ArrayList ?