title: Java - Casting typed list to array
body: <p>This is my method</p>
  
  <pre><code>public AuctionItem[] getOpenAuctions() throws RemoteException {
  
      return itemList.toArray((AuctionItem[]) java.lang.reflect.Array
              .newInstance(itemList.getClass(), itemList.size()));
  
  }
  </code></pre>
  
  <p>and this is my error</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: [Ljava.util.LinkedList; cannot be cast to [LAuction.AuctionItem;
  at Auction.AuctionImpl.getOpenAuctions(AuctionImpl.java:44)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
  at sun.rmi.transport.Transport$1.run(Unknown Source)
  at sun.rmi.transport.Transport$1.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at sun.rmi.transport.Transport.serviceCall(Unknown Source)
  at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
  at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
  at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
  at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
  at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
  at sun.rmi.server.UnicastRef.invoke(Unknown Source)
  at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
  at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
  at $Proxy0.getOpenAuctions(Unknown Source)
  at Seller.SellerMain.main(SellerMain.java:38)
  </code></pre>
  
  <p>What's wrong with it?</p>