title: Specifying which subclass in super class constructor
body: <p>I am trying to first populate a list of generic objects and later instantiate them, and when instantiating them, specify which of the objects each is. </p>
  
  <p>The use-case I am working on is reading a data file and constructing a map, which has various interactable objects. The type of interactable each object is is stored in it's own data file that is directed from the map's data file. Some code for example:</p>
  
  <p>in reading the map:</p>
  
  <pre><code>    if ((char)map[i][j] == '*')
             mapObjects.add(new MapObject());
  </code></pre>
  
  <p>and afterward:</p>
  
  <pre><code>    for (int i = 0 ; i &lt; mapObjects.size() ; i++)
              mapObjects.set (i, new MapObject(in.readLine())); 
              //in.readLine gives the path for the file
  </code></pre>
  
  <p>in MapObject's constructor:</p>
  
  <pre><code>    public MapObject (String in){
      try{
          BufferedReader br = new BufferedReader(new FileReader("src/data/" + in + ".txt"));
          int temp = Integer.parseInt(br.readLine());
          if (temp == 0)
              this = new Door (); //this is apparently not allowed
  
              /*continue to instantiate the Door's fields from the data file*/
      }
  </code></pre>
  
  <p>and the Door class:</p>
  
  <pre><code>    public class Door extends MapObject {
          public Door () {}
      }
  </code></pre>
  
  <p>I realize that this probably isn't the best way to solve this problem, but it raised the curiosity that this doesn't work. Is there any way to do this? Have the super's constructor choose which subclass it will be?</p>