title: Invoking setter method using java reflection
body: <p>I need to invoke the setter methods of a class using reflection, and the code is as below: </p>
  
  <pre><code>try {             
     Method method = myObj.getClass().getMethod("set" + fieldName, new Class[] { value.getClass() });               
     method.invoke(myObj, value);
       } catch (Exception ex) {
           ex.printStackTrace();
       }
  </code></pre>
  
  <p>The <code>value</code> is an <code>ArrayList</code> and the setter method is as below:</p>
  
  <pre><code>public void setNames(List&lt;String&gt; names){
      this.names = names;
  }
  </code></pre>
  
  <p>A <code>java.lang.NoSuchMethodException</code> is thrown when running this code, but when the setter method parameter type is changed to <code>ArrayList</code> from <code>List</code> it executes fine. Is there a way to keep the setter method parameter in super type and still use reflection without manually giving the type of the parameter when getting the method from the class?</p>