title: Casting from Object in Java without getting an unchecked warning
body: <p>I wrote a class that has a map of <code>&lt;String, Object&gt;</code>. I need it to hold arbitrary objects, but at the same time sometimes I need to cast some of those objects, so I'll do something like</p>
  
  <pre><code>HashMap&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();                                                                                 
  Object foo = map.get("bar");                                                                                                                                                                                                         
  if (foo instanceof HashMap) {                                                                                                                                                                                                        
      ((HashMap&lt;String, Integer&gt;) foo).put("a", 5);                                                                                                                                                                                    
  }            
  </code></pre>
  
  <p>which gives the warning</p>
  
  <pre><code>Stuff.java:10: warning: [unchecked] unchecked cast
  found   : java.lang.Object
  required: java.util.HashMap&lt;java.lang.String,java.lang.Integer&gt;
          ((HashMap&lt;String, Integer&gt;) foo).put("a", 5);
  </code></pre>
  
  <p>I suspect it has to do with the use of generics. I can get rid of the error using @SupressWarnings("unchecked"), but I was wondering if there was a better way to do it. Or maybe the fact that I'm getting the warning means I should reconsider what I'm doing. Is there anything I could do, or should I just use @SupressWarnings?</p>