How do I make a HashMap, that maps Integer
or int
to a class instance of a class that extends a specified Class:
public HashMap<Integer, ? extends myClass> myMap = new HashMap<Integer, ? extends myClass>();
This gives a error: Cannot instantiate the type HashMap<Integer,? extends mySuperclass>
(by Eclipse)
I am not too experienced with Java and I really appreciate your answers. To make this a little bit more obvious, this is a short image explaining what I want to achieve: Click this link to see the image.
Trying to add a class that does not extend that Superclass should not work.
I'm really sorry if this has been asked already but I tried searching for a couple of terms and could not find a similar question. There was one quite similar, but I did not understand what the accepted answer said and I don't think it was even the question I am asking here.