title: Converting a List<String> to a List<Integer> (or any class that extends Number)
body: <p>I want to create a very generic utility method to take any Collection and convert it into a Collection of a user selectable class that extends from Number (Long, Double, Float, Integer, etc.)</p>
  
  <p>I came up with this code that uses Google Collections to transform the Collection and to return an Immutable List.</p>
  
  <pre><code>import java.util.List;
  
  import com.google.common.base.Function;
  import com.google.common.collect.ImmutableList;
  import com.google.common.collect.Lists;
  /**
       * Takes a {@code List&lt;String&gt;} and transforms it into a list of the
       * specified {@code clazz}.
       * 
       * @param &lt;T&gt;
       * @param stringValues
       *            the list of Strings to be used to create the list of the
       *            specified type
       * @param clazz
       *            must be a subclass of Number. Defines the type of the new List
       * @return
       */
      public static &lt;T extends Number&gt; List&lt;T&gt; toNumberList(List&lt;String&gt; stringValues, final Class&lt;T&gt; clazz) {
          List&lt;T&gt; ids = Lists.transform(stringValues, new Function&lt;String, T&gt;() {
              @SuppressWarnings("unchecked")
              @Override
              public T apply(String from) {
                  T retVal = null;
                  if (clazz.equals(Integer.class)) {
                      retVal = (T) Integer.valueOf(from);
                  } else if (clazz.equals(Long.class)) {
                      retVal = (T) Long.valueOf(from);
                  } else if (clazz.equals(Float.class)) {
                      retVal = (T) Float.valueOf(from);
                  } else if (clazz.equals(Double.class)) {
                      retVal = (T) Double.valueOf(from);
                  } else {
                      throw new RuntimeException(String.format("Type %s is not supported (yet)", clazz.getName()));
                  }
                  return retVal;
              }
          });
          return ImmutableList.copyOf(ids);
      }
  </code></pre>
  
  <p>It can be used like this:</p>
  
  <pre><code>// Convert List&lt;String&gt; to List&lt;Long&gt;
  List&lt;Long&gt; ids = MiscUtils.toNumberList(productIds, Long.class);
  </code></pre>
  
  <p>Is my code overkill or how would you simplify it and at the same time keep it generic enough?</p>