How do you fill a Java HashMap with multiple instances of related subclasses?
<p>I have a superclass called "Canvas," from which I create several subclasses. I want to store instances of those subclasses in a dictionary. So I tried setting up my code as follows:</p>

<pre><code>public class Main {
    public static void main(String[] args) throws Exception{
        Canvas canvas = new Canvas();



        Menu menu = new Menu();
        Instructions instructions = new Instructions();
        Map&lt;String, Canvas&gt; screens = new HashMap&lt;String, Canvas&gt;();
        screens.put("menu", menu);
        screens.put("instructions", instructions);
</code></pre>

<p>So, being that the things I want to add to the dictionary are all subclasses of my Canvas class, I set up the hashtable to accept that Type. And this works.. for the most part. However, the big problem is that I cannot access any of the subclass' methods. I can only call methods that exist in the superclass.</p>

<p>If I attempt to do something like,  </p>

<pre><code>screens.get("menu").some_func_in_subclass();
</code></pre>

<p>The compiler spits out a "Can not find symbol" message.  </p>

<p>So, if I have something like this: </p>

<pre><code>SuperClass
  |
  |
  +------------------------------------   
        |               |             |
     SubClass1     SubClass2     SubClass3
</code></pre>

<p>How would I store instances of those subclasses in a HashMap? </p>
