 <p>If all you want to do is hide the casts, it's easy as Peter showed. If you want to avoid ClassCastExceptions as well, type erasure dictates you have to pass the class in as a parameter (you can't do <code>instanceof</code> on a generic type). It's a bit messy.</p> <pre><code>class TestGet { private static final Map&lt;String,Object&gt; theMap = new HashMap&lt;String, Object&gt;(); @SuppressWarnings("unchecked") public static &lt;T&gt; T getObject(final String key, final Class&lt;T&gt; clazz) { final Object o = theMap.get(key); return o != null &amp;&amp; clazz.isAssignableFrom(o.getClass()) ? (T) o : null; } } </code></pre> <p>And then</p> <pre><code>JButton b = TestGet.getObject("theButton", JButton.class); </code></pre>