title: BaseFoo cannot be inherited with different arguments: <T,X.Bar<T>> and <T,X.Foo<T>>
body: <p>This is a simplified version of <a href="https://stackoverflow.com/questions/19417082/java-inherited-fluent-method-return-type-in-multiple-level-hierarchies">Java inherited Fluent method return type in multiple level hierarchies</a>.</p>
  
  <p>Given the following code:</p>
  
  <pre><code>public enum X {
      ;
      static interface BaseFoo&lt;T, S extends BaseFoo&lt;T, S&gt;&gt; {
          S foo();
      }
  
      static interface Foo&lt;T&gt; extends BaseFoo&lt;T, Foo&lt;T&gt;&gt; {
          void foo1();
      }
  
      static interface BaseBar&lt;T, S extends BaseBar&lt;T, S&gt;&gt; extends BaseFoo&lt;T, S&gt; {
          S bar();
      }
  
      static interface Bar&lt;T&gt; extends BaseBar&lt;T, Bar&lt;T&gt;&gt;, Foo&lt;T&gt; {
          void bar1();
      }
  
  }
  </code></pre>
  
  <p>run <code>javac X.java</code> I get the error message:</p>
  
  <pre><code>X.java:15: error: BaseFoo cannot be inherited with different arguments: &lt;T,X.Bar&lt;T&gt;&gt; and &lt;T,X.Foo&lt;T&gt;&gt;
      static interface Bar&lt;T&gt; extends BaseBar&lt;T, Bar&lt;T&gt;&gt;, Foo&lt;T&gt; {
             ^
  </code></pre>
  
  <p>Anyone has any solution?</p>
  
  <p><strong>Disclaim</strong>: I am trying to use the pattern to implement the <a href="http://en.wikipedia.org/wiki/Fluent_interface" rel="nofollow noreferrer">fluent interface</a> across a container class inheritance hierarchy.</p>
  
  <p><strong>Background</strong>: to make it easier for people to understand why I need this, here is the story. I want to create a container family: <code>Traversal</code> &lt;- <code>Sequence</code> &lt;- <code>List</code>. So <code>Traversal</code> has a method <code>Traveral&lt;T&gt; accept(Visitor&lt;T&gt;)</code> (no <a href="https://stackoverflow.com/questions/2723397/java-generics-what-is-pecs">PECS</a> for short), this method should always return <code>this</code> after iterating the visitor through the elements. When I have a <code>List</code> type, I want the method return <code>List&lt;T&gt;</code> instead of <code>Traversal&lt;T&gt;</code> because I want to make it possible to call something like <code>myList.accept(v).head(15)</code>, where <code>head(int)</code> is a method of <code>List</code> not <code>Traversal</code></p>