title: How to refer to the implementing class in a generic interface
body: <p>Let's say I want to define an interface which would describe any tree structure of objects that contain similar objects.  An obvious implementation would be:</p>
  
  <pre><code>interface HasChildren {
      val children: Sequence&lt;HasChildren&gt;
  }
  
  class Branch(val children: Sequence&lt;Branch&gt;) : HasChildren
  </code></pre>
  
  <p>The more or less obvious problem with this is that while the children of a <code>Branch</code>  must always, in turn be <code>Branch</code>, that has been lost through the interface, and I have to explicitly typecast them back.</p>
  
  <p>Is there a way, similar to <code>Self</code> in Swift:</p>
  
  <pre><code>protocol HasChildren {
      let children : Sequence&lt;Self&gt; { get }
  }
  </code></pre>
  
  <p>to not lose the implementing class type?</p>