title: How to use Java reflection to check a given class is implements Iterable<? extends T>, for any given T
body: <p>I have a specific target type (decided at runtime), and an iterable class that I'm comparing to it. I'm trying to write a method that checks the generic parameters of the class, to see if it's an iterable of something that subclasses my target type. Examples:</p>
  
  <pre><code>Class&lt;?&gt; X = SomeObject.class;
  
  matches(X, new ArrayList&lt;SomeObject&gt;()) -&gt; true
  matches(X, new ArrayList&lt;SubclassOfSomeObject&gt;()) -&gt; true
  matches(X, new ArrayList&lt;SomeOtherObject&gt;()) -&gt; false
  matches(X, new ArrayList()) -&gt; true (I think?)
  matches(X, new Iterable&lt;SomeObject&gt;() { ... }) -&gt; true
  matches(X, new ListOfSomeObjects()) -&gt; true 
                         (where ListOfSomeObjects extends Iterable&lt;SomeObject&gt;)
  </code></pre>