title: searching keys of subclass in HashMap
body: <p>just tried to do something like:</p>
  
  <pre><code>public class GameMap {
  
  protected HashMap&lt;Sector, Integer[]&gt; mapping;
  
  protected void loadMapFromFile(String fileLocation, int numPlayers) {
  
      .
      //Other stuff
      .
      .
  
      case "ALIENSECT":
  
      Integer[] someValue = {5};
      mapping.put(new AlienSector(row, col), someValue);
      break;
  }
  
  public justATestMethod() {
  
      System.out.println(mapping.containsKey(new Sector(6, 'L')));
  }
  </code></pre>
  
  <p>Where <code>AlienSector</code> is a subclass of <code>Sector</code>.</p>
  
  <p>But when I try to do this in another class:</p>
  
  <pre><code>   mappa.justATestMethod();
  </code></pre>
  
  <p>The result is "false".</p>
  
  <p>Instead if I rewrite the method "justATestMethod()" like this:</p>
  
  <pre><code>System.out.println(mapping.containsKey(new AlienSector(6, 'L')));
  </code></pre>
  
  <p>Result is "true".</p>
  
  <p>I obtain "true" also changing this lines of "loadMapFromFile" method:</p>
  
  <pre><code>case "ALIENSECT":
  
  Integer[] someValue = {5};
  mapping.put(new AlienSector(row, col), someValue);
  break;
  </code></pre>
  
  <p>This way:</p>
  
  <pre><code>case "ALIENSECT":
  
  mapping.put(new Sector(row, col), new Integer[1]);
  Integer[] aCazzo = {5};
  mapping.put(new AlienSector(row, col), aCazzo);
  break;
  </code></pre>
  
  <p>That is first filling the HashMap with <code>Sector</code> objects keys and then assigning keys of <code>AlienSector</code> objects.</p>
  
  <p>Someone could explain me why this happens? <code>AlienSector</code> is a subclass of <code>Sector</code>, why Java doesn't recognize the presence of a <code>Sector</code> in the HashMap keys if I simply instantiate a subclass of it without first instantiate the key with an istance of the superclass "Sector" itself?</p>