Datastructure to map Class objects to values while considering superclasses?
<p>Is there a map like data structure that uses Java Class objects as keys but uses fallback to superclasses if no mapping is found? Let me give a short example:</p>

<pre><code>ClassMap&lt;Integer&gt; map = new ClassMap&lt;Integer&gt;();
map.put(Object.class, 1);
map.put(Number.class, 2);

assertEquals(1, map.get(String.class));
assertEquals(2, map.get(Number.class));
assertEquals(2, map.get(Double.class));
</code></pre>

<p>I know that I could do the fallback manually, e.g.</p>

<pre><code>WeakHashMap&lt;Class&lt;?&gt;, Integer&gt; map = // snip

Class&lt;?&gt; cls = Double.class;
Integer i;
do {
  i = map.get(cls);
  cls = cls.getSuperclass();
} while (i == null &amp;&amp; cls != null);
</code></pre>

<p>Still I'm interested in existing or alternative solutions.</p>
