title: Getting Type instance of implemented interface with type parameters applied
body: <p>Given a Type instance (which may be a Class or ParameterizedType), I need to get the specific Type of an interface implemented by the class. Without generics this is easy, call getInterfaces() on a Class instance and you're done. However, I need this to work even when the implemented interface has its own type parameters that may or may not depend on the type parameters of the original class itself.</p>
  
  <p>Some examples, the function should return Iterable&lt;Integer&gt; when given a class</p>
  
  <pre><code>class Foo implements Iterable&lt;Integer&gt; {}
  </code></pre>
  
  <p>but must also return Iterable&lt;String&gt; given the class</p>
  
  <pre><code>class Bar&lt;T&gt; implements Iterable&lt;T&gt; {}
  </code></pre>
  
  <p>and a ParmeterizedType representing Bar&lt;String&gt;</p>
  
  <p>Is there an easy way to do this with built in reflection, third party tools etc?</p>
  
  <p>To clarify, this needs to work not only with type instances retrieved via literals (Foo.class etc), but also those returned via reflection that can contain applied type parameters, for example the return type returned via reflection from the method</p>
  
  <pre><code>static Bar&lt;String&gt; magic() { ... }
  </code></pre>
  
  <p>This would be a ParameterizedType referencing the raw Bar class and the String type argument.</p>