title: How do I declare a member with multiple generic types that have non-trivial relationships?
body: <p>Here is what I would like to write in my java code:</p>
  
  <pre><code>private &lt;A extends Action&lt;R&gt;, R extends Result&gt; MyType&lt;A,R&gt; member;
  </code></pre>
  
  <p>This is invalid syntax however. So I end up writing:</p>
  
  <pre><code>private MyType&lt;? extends Action&lt;? extends Result&gt;, ? extends Result&gt; member;
  </code></pre>
  
  <p>But this disregard the fact that both classes derived from <code>Result</code> are the same. My class methods all enforce this relationship, so I can be sure that MyType enforces it, but I still have to unsafely typecast <code>member</code> in some instances.</p>
  
  <h2>More details</h2>
  
  <p>Here is the precise version of what I want to do, although it is much more criptic:</p>
  
  <p>I wish I could do:</p>
  
  <pre><code>private &lt;A extends Action&lt;R&gt;, R extends Result&gt; 
      Map&lt; Class&lt;A&gt;, ActionHandler&lt;A,R&gt; &gt; handlers;
  </code></pre>
  
  <p>Instead I have to do:</p>
  
  <pre><code>private Map&lt; Class&lt; ? extends Action&lt;? extends Result&gt; &gt;, 
               ActionHandler&lt;? extends Action&lt;? extends Result&gt;, 
                             ? extends Result&gt; &gt; handlers;
  </code></pre>
  
  <p>My methods enforce the desired relationship and look like that:</p>
  
  <pre><code>public &lt;A extends Action&lt;R&gt;, R extends Result&gt; void addHandler( 
      ActionHandler&lt;A, R&gt; handler ) {
    handlers.put( handler.getActionType(), handler );
  }
  </code></pre>
  
  <p>I would like the following method:</p>
  
  <pre><code>public &lt;A extends Action&lt;R&gt;, R extends Result&gt; ActionHandler&lt;A, R&gt; 
      findHandler( A action ) {
    return handlers.get( action.getClass() );
  }
  </code></pre>
  
  <p>But this doesn't work: I have to add a cast and a <code>@SuppressWarnings("unchecked")</code>.</p>
  
  <h2>Things I tried</h2>
  
  <p>I tried creating a new class just for that purpose :</p>
  
  <pre><code>public class MyMap &lt;A extends Action&lt;R&gt;, R extends Result&gt; extends 
      HashMap&lt; Class&lt;A&gt;, ActionHandler&lt;A,R&gt; &gt; { ... }
  
  MyMap&lt; ?, ? &gt; handlers;
  </code></pre>
  
  <p>But it didn't work, I still need a cast.</p>