I have several classes that all extend a certain class. I want to use a HashMap
or something similar to hold an ArrayList
for each of those classes, as kind of shown below.
HashMap<? extends MasterClass, ArrayList<? extends MasterClass>>
I want to call get
with the extended class. This should return the ArrayList
of that class. Is this possible?
get(Class);
You need to have Class<? extends MasterClass>
Class<? extends MasterClass>
as key of your map:
Map<Class<? extends MasterClass>, List<? extends MasterClass>> map
= new HashMap<Class<? extends MasterClass>, List<? extends MasterClass>>();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.