title: Java, parent static method returning child type
body: <p>I'm new to java and Generics so please bear with me. I don't even know if this is possible. I've looked around and although there seem to be a few posts about this here and there I haven't found one that addresses my specific case clearly enough for me to understand what to do.</p>
  
  <p>I basically have a static method in the parent class and would like it to return various types based on which child calls it. The trick here is that said child class that is returned also needs to be instantiated within the method. </p>
  
  <p>Here's what I mean:</p>
  
  <pre><code>public class Parent {
  
     public String value;
  
     public Parent(String value)
     {
        this.value = value;
     }
  
     public static &lt;T extends Parent&gt; T load(DataStorage data, String key)
     {
        T inst = new ???(data.getValue(key));
        return inst;
     }
  }
  
  public class Child extends Parent {
  }
  
  Child child = Child.load(dataStore, "key"); // random dataStore instance
  </code></pre>
  
  <p>I'm not sure where to go from here. What do I use in place of <code>???</code> which should be whichever child (or <code>Parent</code>) runs the <code>load()</code> ? Do I need to also do something along the lines of <code>Child.&lt;Child&gt;load()</code>?</p>
  
  <p><strong>I'm open to alternative designs if you feel I'm mistaking in trying to do things like this. I don't like the idea of having to play around with Reflection in this situation (feels a little hacky)</strong></p>
  
  <p>Thanks in advance, I really appreciate it.</p>