title: Get parameter Type from dynamic method using reflection
body: <p>I've got this bit of code to get a setter method from a dynamic class. But the parameters can be a <code>java.lang.String</code> or <code>java.lang.Long</code>. How can I dynamically get the parameter type?</p>
  
  <pre><code>public Method getDynMethod(Class aClass, String methodName) {
      Method m = null;
      Class[] paramTypes = new Class[1];
      paramTypes[0] = String.class;
      try {
          m = aClass.getMethod(methodName, paramTypes);
      } catch (NoSuchMethodException nsme) {
          nsme.printStackTrace();
      }
      return m;
  }
  </code></pre>
  
  <p>This is the code that calls it</p>
  
  <pre><code>Class c = getDynClass(a.getAssetType().getDBTableName());
          for (Long l : map.keySet()) {
              AssetProperties ap = new AssetProperties();
              ap.setAssetTypeProperties(em.find(AssetTypeProperty.class, l));
              ap.setAssets(a);
              ap.setValue(map.get(l));
              a.getAssetProperties().add(ap);
              String methodName = "set" + ap.getAssetTypeProperties().getDBColumn();
              Method m = getDynMethod(c, methodName);
              try {
                  String result = (String) m.invoke(c.newInstance(), ap.getValue());
                  System.out.println(result);
              } catch (IllegalAccessException iae) {
                  iae.printStackTrace();
              } catch (InvocationTargetException ite) {
                  ite.printStackTrace();
              } catch (InstantiationException ie) {
                  ie.printStackTrace();
              }
  
          }
  </code></pre>
  
  <p>I could pass another parameter to the method but I still would not know what the parameter type would be</p>