title: Using reflection to get a method; method parameters of interface types aren't found
body: <p>How do I get a method using reflection based on a parameter value when the parameter type is an interface?</p>
  <p>In the following case (based on <a href="http://www.oracle.com/technetwork/articles/javase/index-142890.html" rel="nofollow noreferrer">this example</a>), <code>newValue</code> would be a <code>List&lt;String&gt;</code> called <code>foo</code>. So I would call <code>addModelProperty(&quot;Bar&quot;, foo);</code> But this only works for me if I don't use the interface and only use <code>LinkedList&lt;String&gt; foo</code>. How do I use an interface for <code>newValue</code> and get the method from <code>model</code> that has an interface as the parameter <code>addBar(List&lt;String&gt; a0)</code>?</p>
  <pre class="lang-java prettyprint-override"><code>public class AbstractController {
    private final AbstractModel model;
    public setModel(AbstractModel model) {
      this.model = model;
    }
    protected void addModelProperty(String propertyName, Object newValue) {
      try {
        Method method = getMethod(model.getClass(), &quot;add&quot; + propertyName, newValue);
        method.invoke(model, newValue);
      } catch (NoSuchMethodException e) {
      } catch (InvocationTargetException e) {
      } catch (Exception e) {}
    }
    private Method getMethod(Class clazz, String name, Object parameter) {
      return clazz.getMethod(name, parameter.getClass());
    }
  }
  
  public class AbstractModel {
    protected PropertyChangeSupport propertyChangeSupport;
    protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
      propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
    }
  }
  
  public class Model extends AbstractModel {
    public void addList(List&lt;String&gt; list) {
      this.list.addAll(list);
    }
  }
  
  public class Controller extends AbstractController {
    public void addList(List&lt;String&gt; list) {
      addModelProperty(list);
    }
  }
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>public void example() {
    Model model = new Model();
    Controller controller = new Controller();
    List&lt;String&gt; list = new LinkedList&lt;String&gt;();
    list.add(&quot;example&quot;);
  // addList in the model is only found if LinkedList is used everywhere instead of List
    controller.addList(list);
  }
  </code></pre>