title: Using Java Reflections to find Collection's element type?
body: <p>Consider the following Java code:</p>
  
  <pre><code>public class Test
  {
      private Foo&lt; String, String &gt; foo1;
      private Foo&lt; Integer, Integer &gt; foo2;
  }
  
  public class Foo&lt; T, V &gt;
  {
      private Bar&lt; V &gt; bar;
      private T a;
  }
  
  public class Bar&lt; T &gt;
  {
      @MyAnnotation
      private List&lt; T &gt; list;
  }
  </code></pre>
  
  <p>First, starting with the class named 'Test', I'm searching all fields recursively, which are annotated with 'MyAnnotation' and whose type is derived from 'java.lang.Collection'. For the given example, the results would be:</p>
  
  <ul>
  <li>Test.foo1.bar.list</li>
  <li>Test.foo2.bar.list</li>
  </ul>
  
  <p>It's obviosly clear, that the first one can only take strings for its elements, whereas the second one can only take integers.</p>
  
  <p><strong>My Question is: What is the best (easiest) way to find all Collection fields annotated with 'MyAnnotation' and <em>tell their element type</em>?</strong></p>
  
  <p>Finding annotated fields from type java.lang.Collection is not the problem. But how can we get a result which looks like the following one for the given example?</p>
  
  <ul>
  <li>Test.foo1.bar.list&lt; String ></li>
  <li>Test.foo2.bar.list&lt; Integer ></li>
  </ul>
  
  <p>I've tried several approaches, which always gave me 'Object' as the collection's element type instead of 'String'.</p>
  
  <p>I'm really stuck on this.
  Many thanks in advance!</p>