title: Generic return type from a generic method
body: <p>Consider a generic method definition like this:</p>
  
  <pre><code>public static &lt;T&gt; T getParameter(final Context context, final ContextParameter contextParameter, final Class&lt;T&gt; clazz) {
      return (T) context.get(contextParameter.name());
  }
  </code></pre>
  
  <p>Works perfectly to get any type of object until you try a generic object like List&lt;String&gt;. The only way I could make it work was like this:</p>
  
  <pre><code> final List&lt;String&gt; fileNames = 
               (List&lt;String&gt;) ContextUtils.getParameter(context,
                               ContextParameter.EOF_FILE_NAMES_TO_ZIP, List.class);
  </code></pre>
  
  <p>But that requires an extra cast, removing the purpose of having the method. Is there a way to be able to provide <code>List&lt;String&gt;.class</code> or something similar to the method? (I know that type erasure prevents <code>List&lt;String&gt;</code> to exist but maybe there is a way to do it).</p>
  
  <p><em>Note: With making it work I mean without having a type safety warning. I'm aware that the code would work as it is but it is not type safe.</em></p>