Use of generics
<p>I'm trying to expire objects from a hashmap if they haven't been used after some time. </p>

<p>I have maps on different types of objects and would like to handle them using generics to avoid code duplication.</p>

<pre><code>private Map&lt;String,EvictableObject&lt;ObjectA&gt;&gt; _objectsA = new HashMap&lt;String,EvictableObject&lt;ObjectA&gt;&gt; ();
private Map&lt;String,EvictableObject&lt;ObjectB&gt;&gt; _objectsB = new HashMap&lt;String,EvictableObject&lt;ObjectB&gt;&gt; ();
private Map&lt;String,EvictableObject&lt;ObjectC&gt;&gt; _objectsC = new HashMap&lt;String,EvictableObject&lt;ObjectC&gt;&gt; ();
private Map&lt;String,EvictableObject&lt;ObjectD&gt;&gt; _objectsD = new HashMap&lt;String,EvictableObject&lt;ObjectD&gt;&gt; ();


private void startEvictionTask() {

    Runnable evictionTask = new Runnable() {
        public void run () {
            runEviction(_objectsA);
            runEviction(_objectsB);
            runEviction(_objectsC);
            runEviction(_objectsD);
        }

        private void runEviction (Map&lt;String, EvictableObject&lt;?&gt;&gt; table) {

            final long expirationPeriod = 60 * 60 * 1000; // 60 minutes (in ms)

            synchronized (table) {
                for (Map.Entry&lt;String,EvictableObject&lt;? extends Object&gt;&gt; entry : table.entrySet()) {
                    if (entry.getValue().getAccessedSince() &gt; expirationPeriod)
                        table.remove(entry.getKey());
                }
            }

        }
    };

    MyThreadPool.getScheduledExecutor().scheduleWithFixedDelay(evictionTask, 65*60, 5*60, TimeUnit.SECONDS);
}
</code></pre>

<p>But none of what I tried seem to work as a declaration of the runEviction method. And the compiler keeps saying that the actual argument can't be converted to the declared method parameter.</p>

<p>I've tried:</p>

<pre><code>private void runEviction (Map&lt;String, EvictableObject&lt;?&gt;&gt; table)
</code></pre>

<p>,</p>

<pre><code>private void runEviction (Map&lt;String, EvictableObject&lt;B&gt;&gt; table)
</code></pre>

<p>,</p>

<pre><code>private void runEviction (Map&lt;String, EvictableObject&lt;B extends Object&gt;&gt; table)
</code></pre>

<p>and</p>

<pre><code>private void runEviction (Map&lt;String, EvictableObject&lt;? extends Object&gt;&gt; table)
</code></pre>

<p>Is there no way to do this?</p>
