title: How to check that a method returns Collection<Foo> in Java?
body: <p>I wish to a check if a method exists in an interface based on its signatures.</p>
  
  <p>The signature that the method should have is:</p>
  
  <pre><code>Collection&lt;Foo&gt; methodName(Spam arg0, Eggs arg1, ...)
  </code></pre>
  
  <p>I can find the methods via <code>Class.getMethods()</code> 
  then find the name, parameters and return type respectively with <code>method.getName()</code>,  <code>method.getParameterTypes()</code> and <code>method.getReturnType()</code>.</p>
  
  <p>But what do I compare the return type to in order to ensure that only methods that return <code>Collection&lt;Foo&gt;</code> are chosen, and not other collections?</p>
  
  <pre><code>method.getReturnType().equals(Collection.class) 
  </code></pre>
  
  <p>Since the above will be true for all methods that return a collection, not just for those that return a <code>Foo</code> Collection.</p>