title: Java Generics with Class <T>
body: <p>So I have a map: </p>
  
  <pre><code>Map&lt;String, Class&gt; format = new HashMap&lt;String, Class&gt;();
  </code></pre>
  
  <p>And I would add elements to it like this:</p>
  
  <pre><code>format.put("Vendor Number", Integer.class);
  format.put("Vendor Dispatch", Date.class); 
  ....
  </code></pre>
  
  <p>I have a generic method as follows:</p>
  
  <pre><code>public static &lt;T&gt; T verifyType(String name, Class&lt;T&gt; type) {
      if (type == Integer.class) {
          return type.cast(new Integer(Integer.parseInt(name)));
      }
               ......
      return null;
  }
  </code></pre>
  
  <p>Now this piece of code works great with no compiler issues: </p>
  
  <pre><code>Integer i = verifyType("100",Integer.class);
  </code></pre>
  
  <p>But, when I try this: </p>
  
  <pre><code>    Integer i = verifyType("100",format.get("Vendor Number"));
  
  OR 
  
      Class type = Integer.class
      Integer i = verifyType("100",type);
  </code></pre>
  
  <p>Compiler shows me this warning: 
  Type safety: Unchecked invocation verifyType(String,Class) of the generic method verifyType(String, Class) </p>
  
  <p>That leaves me puzzled... please help...</p>