a java generic programming question
<p>I have a class A like this:</p>

<pre><code>public class A&lt;T extends Number&gt;
{
 ....
}
</code></pre>

<p>In another class I have this method:</p>

<pre><code>public Hashtable&lt;String, A&gt; createAHashtable()
    {
        Hashtable&lt;String, A&gt; hTable = new Hashtable&lt;String, A&gt;();

        return hTable;
    }
</code></pre>

<p>There is a warning for parameter A because it is generic class. So should I do this:</p>

<pre><code>public Hashtable&lt;String, A &lt;?&gt;&gt; createAHashtable()
        {
            Hashtable&lt;String, A&lt;?&gt;&gt; hTable = new Hashtable&lt;String, A&lt;?&gt;&gt;();

            return hTable;
        }
</code></pre>

<p>or do this:</p>

<pre><code>public Hashtable&lt;String, A &lt;? extends Number&gt;&gt; createAHashtable()
{
Hashtable&lt;String, A&lt;? extends Number&gt; hTable = new Hashtable&lt;String, A&lt;? extends Number&gt;();

return hTable;
}
</code></pre>

<p>or ....???</p>

<p><strong>EDIT:</strong></p>

<p>Tried this (as suggested by Dilum)</p>

<pre><code>public &lt;T extends Number&gt; Hashtable&lt;String, A&lt;T&gt;&gt; createAHashtable()
    {
        Hashtable&lt;String, A&lt;T&gt;&gt; hTable = 
                new Hashtable&lt;String, A&lt;T&gt;&gt;();
        A&lt;Float&gt; constraint = new A&lt;Float&gt;();
        hTable.put("test", constraint);

        return hTable;
    }
</code></pre>

<p>But it is invalid to "put" my Float A.</p>

<p>Maybe the wildcard is the way to go.</p>

<p><strong>EDIT 2:</strong> </p>

<p>Based on Dilum's suggestion, the following code (cast to A when put a Float A into the Hashtable) has no error but warning it is unsafe cast. Why we need the cast?</p>

<pre><code>public &lt;T extends Number&gt; Hashtable&lt;String, A&lt;T&gt;&gt; createAHashtable()
        {
            Hashtable&lt;String, A&lt;T&gt;&gt; hTable = 
                    new Hashtable&lt;String, A&lt;T&gt;&gt;();
            A&lt;Float&gt; constraint = new A&lt;Float&gt;();
            hTable.put("test", (A&lt;T&gt;)constraint);

            return hTable;
        }
</code></pre>
