How to pass generic list class as an argument to generic method in Java?
<p>I want to have a method which would return required type of objects extracted from a map.
Here is an example</p>

<pre><code>Map&lt;String,Object&gt; map = new HashMap&lt;&gt;();
map.put("ids", Arrays.asList(5,345,45645)); 
map.put("id", 325); 

&lt;T&gt; T get(String arg, Class&lt;T&gt; clazz) {
    return (T) map.get(arg);
}
</code></pre>

<p>Then, for example, Integer can be gotten with this code</p>

<pre><code>Integer id = get("id", Integer.class);
</code></pre>

<p>But when I'm trying to get a list of objects in these ways</p>

<pre><code>List&lt;Integer&gt; ids = get("ids", new ArrayList&lt;Integer&gt;().getClass());
List&lt;Integer&gt; ids = get("id", List.class);
</code></pre>

<p>Intellij IDEA warns: <code>Unchecked assignment: 'java.util.ArrayList' to 'java.util.List&lt;java.lang.Integer&gt;'</code></p>

<p>I expected something like <code>List&lt;Integer&gt;.class</code> (by analogy to <code>Integer.class</code>, <code>Boolean.class</code> etc...) what would be used as</p>

<pre><code>List&lt;Integer&gt; ids = get("ids", List&lt;Integer&gt;.class`)
</code></pre>

<p>but this is not compiled.</p>

<p>So is there a solution?</p>