title: Reconstructing generic types at runtime with Guice via Types and TypeLiterals
body: <p>I have a few types that are like this</p>
  
  <pre><code>// a value that is aware of its key type (K)
  Bar&lt;K&gt;
  // something that deals with such values and keys
  Foo&lt;V extends Bar&lt;K&gt;, K&gt;
  </code></pre>
  
  <p>How would one recreate Foo such that you could consume it in Guice?  The bit I'm stuck on is how to cross reference the K from Bar to the 2nd parameterized type of Foo. </p>
  
  <p>So for example,</p>
  
  <pre><code>WildcardType kType = Types.subtypeOf(Object.class);
  WildcardType barType = 
     Types.subtypeOf(Types.newParameterizedType(Bar.class, pipeKey));
  ParameterizedType fooType = 
     Types.newParameterizedType(Foo.class, pipelineableType, pipeKey);
  </code></pre>
  
  <p>Really this seems wrong as it's basically:</p>
  
  <pre><code>Foo&lt;V extends Bar&lt;? extends Object&gt;, ? extends Object&gt; 
  </code></pre>
  
  <p>Which is not the same thing as:</p>
  
  <pre><code>Foo&lt;V extends Bar&lt;K&gt;, K&gt;
  </code></pre>
  
  <p>As in the latter case I <em>know</em> that K is a consistent type.</p>
  
  <p>Any ideas?</p>
  
  <p>Cheers</p>
  
  <p>Matt</p>