title: Runtime error: Array of Lists with generics in Java
body: <p>I'm attempting the following to implement a separate chaining hash table with generics:</p>
  
  <pre><code>// hash table class
  protected List&lt;HashEntry&lt;K, V&gt;&gt;[] bucket;
  this.bucket = (List&lt;HashEntry&lt;K, V&gt;&gt;[]) new Object[capacity];(*)
  (...)
  // main program
  HashTableMapSC&lt;Integer, String&gt; hashSC = new HashTableMapSC&lt;Integer,String&gt;(7);
  </code></pre>
  
  <p>I get the following run-time error:</p>
  
  <blockquote>
    <p>[Ltablashash.HashTableMapSC$HashEntry; cannot be cast to [Ljava.util.List;</p>
  </blockquote>
  
  <p>located at (*)</p>
  
  <p>HashEntry is just a simple private class that holds key,pair values.</p>
  
  <p>I'm aware that this would work:</p>
  
  <pre><code>protected List&lt;List&lt;HashEntry&lt;K,V&gt;&gt;&gt; bucket;
  </code></pre>
  
  <p>but as I'm been asked to do it that way,I would like to know if it's possible.</p>
  
  <p>Thanks</p>