title: Cast to an array of Message
body: <p>Good Afternoon in my timezone.</p>
  
  <p>I have a "simple" question.</p>
  
  <p>I have an ArrayList , but when i transform this ArrayList to array using the method toArray from the ArrayList object and cast it to Message[] it throws an java.lang.ClassCastException ? The Message class belongs to package "javax.mail.Message"
  Snippet of code :</p>
  
  <pre><code> List&lt;Message&gt; messageList = new ArrayList&lt;Message&gt;();
      --code to fullfill the List
     (Message[]) messageList.toArray();
  </code></pre>
  
  <p>Throws and exception: 
  <strong><em>Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljavax.mail.Message;</em></strong></p>
  
  <p>Can anyone explain me why this happen ?</p>
  
  <p>With the best regards</p>