title: Instantiating a generic type object with the same type as its superclass
body: <p>I am wondering if it is possible to create objects that are of generic type with the same type as the class it is contained in.</p>
  
  <p>For example, consider this object</p>
  
  <pre><code>public class Foo&lt;T&gt; {
  
     private T variable;
  
     Foo() {
  
     }
  }
  </code></pre>
  
  <p>Now consider this</p>
  
  <pre><code>public class Bar&lt;T&gt; {
  
     private Foo foo;
  
     Bar() {
        foo = (T) new Foo();
     }
  }
  </code></pre>
  
  <p>I want the data type of the foo object inside the bar class to be the same data type that bar is instantiated as.</p>