title: Java: how to convert a List<?> to a Map<String,?>
body: <p>I would like to find a way to take the object specific routine below and abstract it into a method that you can pass a class, list, and fieldname to get back a Map.
  If I could get a general pointer on the pattern used  or , etc that could get me started in the right direction.</p>
  
  <pre><code>  Map&lt;String,Role&gt; mapped_roles = new HashMap&lt;String,Role&gt;();
      List&lt;Role&gt; p_roles = (List&lt;Role&gt;) c.list();
      for (Role el :  p_roles) {
          mapped_roles.put(el.getName(), el);
      }
  </code></pre>
  
  <p>to this? (Pseudo code)</p>
  
  <pre><code>  Map&lt;String,?&gt; MapMe(Class clz, Collection list, String methodName)
    Map&lt;String,?&gt; map = new HashMap&lt;String,?&gt;();
      for (clz el :  list) {
          map.put(el.methodName(), el);
      }
  </code></pre>
  
  <p>is it possible?</p>