why is there an exception for the following java code?
<p>Why does I get an exception</p>

<pre><code>Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
        at Main.main(Main.java:12)
</code></pre>

<p>for the following code?</p>

<pre><code>import java.util.Set;
import java.util.HashMap;


public class Main
{
        public static void main(String args[])
        {
                HashMap&lt;Integer, Double&gt; h = new HashMap&lt;Integer,Double&gt;();
                h.put(1, 2.2);

                Integer[] keys = (Integer[])h.keySet().toArray();
        }
}
</code></pre>

<p>Shouldn't it be possible to cast the Object[] returned to Integer[], since the key set contains integers? What is a fast alternative to copy the key set to an integer array?</p>
