 <p>This type information is erased during compilation (see <a href="http://gafter.blogspot.co.uk/2006/11/reified-generics-for-java.html" rel="nofollow">Neal Gafter's "Reified Generics for Java"</a>).</p> <p>On a practical note, you can guard your collections using the <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html" rel="nofollow">Collections</a> utility methods:</p> <pre><code>Class&lt;String&gt; type = String.class; Map&lt;String, String&gt; hashMap = new HashMap&lt;&gt;(); Map&lt;String, String&gt; map = Collections.checkedMap(hashMap, type, type); Map rawType = map; // pre-Java 1.5 code knows nothing about generics rawType.put(1, 2); // throws ClassCastException at runtime </code></pre>