title: Instantiate a concrete Java class that uses recursive generics in Kotlin
body: <p>Can I instantiate a concrete Java class that uses recursive generics in Kotlin, if so then how?</p>
  
  <p><strong>Details</strong></p>
  
  <p>I am trying to instantiate a Java class that uses recursive generics similar to the example below. I found a work around for wrapping the Java class in a new class, but that feels like I am sidestepping a problem that I should be able to handle directly. </p>
  
  <p><em>Java Class With Recursive Generics</em></p>
  
  <pre><code>public class MyLegacyClass&lt;T extends MyLegacyClass&lt;T&gt;&gt; {
      // implementation ...
  }
  </code></pre>
  
  <p><em>How it is Instantiated in Java</em></p>
  
  <pre><code>// In Java we just ignore the generic type...
  MyLegacyClass myLegacyClass = new MyLegacyClass();
  </code></pre>
  
  <p><em>Failed Attempts to Instantiate in Kotlin</em></p>
  
  <pre><code>class myClass {
      // Error: One type argument expected for class...
      val x: MyLegacyClass = MyLegacyClass()
  
      // Still 'Error: One type argument expected for class..' You start to see the problem here. 
      val y: MyLegacyClass&lt;MyLegacyClass&lt;MyLegacyClass&lt;MyLegacyClass&gt;&gt;&gt; = MyLegacyClass()
  }
  </code></pre>
  
  <p><em>Kotlin workaround</em></p>
  
  <pre><code>class MyLegacyClassWrapper : MyLegacyClass&lt;MyLegacyClassWrapper&gt;()
  
  class myClass {
      val x: MyLegacyClass&lt;MyLegacyClassWrapper&gt; = MyLegacyClassWrapper()
  }
  </code></pre>