title: Is there any way to declare that an inner class has the same generic type as the outer?
body: <p>Is there any way to reuse the generic parameters of an outer class by an inner class?</p>
  <hr />
  <p>I have the following class</p>
  <pre><code>public class TaggedUnionBuilder&lt;L,R&gt;{
      private final Class&lt;L&gt; leftClass;
      private final Class&lt;R&gt; rightClass;
  
      public TaggedUnionBuilder( Class&lt; L &gt; leftClass, Class&lt; R &gt; rightClass ) {
          this.leftClass = leftClass;
          this.rightClass = rightClass;
      }
  
      TaggedUnion&lt;L,R&gt; left( L aLeft ){
          return new TaggedUnion&lt;&gt;( true, aLeft  );
      }
  
      TaggedUnion&lt;L,R&gt; right( R aRight ){
          return new TaggedUnion&lt;&gt;( false, aRight  );
      }
  
  
      public class TaggedUnion&lt;L,R&gt;{
          private final boolean isLeftClass;
          private final Object value;
  
  
          private TaggedUnion( boolean isLeftClass, Object value ) {
              this.isLeftClass = isLeftClass;
              this.value = value;
          }
  
          L left(){
              //vvv compiler error vvv
              return leftClass.cast( value );
              //^^^ compiler error ^^^
          }
  
          R right(){
              //vvv compiler error vvv
              return rightClass.cast( value );
              //^^^ compiler error ^^^
          }
  
          boolean isLeft(){
              return isLeftClass;
          }
  
          boolean isRight(){
              return !isLeftClass;
          }
      }
  
  }
  </code></pre>
  <p>However, I have a get the errors:</p>
  <blockquote>
  <p>java: incompatible types: L cannot be converted to L</p>
  <p>java: incompatible types: R cannot be converted to R</p>
  </blockquote>
  <p>in the <code>left()</code> and <code>right()</code> methods.</p>
  <p>It seems like the declaration of <code>L</code> and <code>R</code> in <code>TaggedUnion</code> are shadowing the declaration in <code>TaggedUnionBuilder</code>. If I remove the generic parameter declaration for <code>TaggedUnion</code> I cannot return it as a generic type.</p>
  <p>If I remove the generic parameters off of <code>TaggedUnion</code> I get the errors</p>
  <blockquote>
  <p>java: type TaggedUnionBuilder.TaggedUnion does not take parameters</p>
  </blockquote>