title: How to fix this java.lang.ClassCastException: [B cannot be cast to java.util.List
body: <p>I'm creating a digital signature software in Java and I wanna the software to verify the message with parameters (string filename, string keyfile).
  But I've got this exception at line </p>
  
  <p><code>this.list2 = (List&lt;byte[]&gt;) in.readObject();</code></p>
  
  <blockquote>
    <p>java.lang.ClassCastException: [B cannot be cast to java.util.List. How
    to solve this?</p>
  </blockquote>
  
  <pre><code>import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.io.*;
  import java.nio.file.Files;
  import java.security.*;
  import java.security.spec.PKCS8EncodedKeySpec;
  import java.security.spec.X509EncodedKeySpec;
  import java.util.List;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.swing.*;
  
  private boolean verifySignature(byte[] data, byte[] signature, String 
  keyFile) throws Exception {
      Signature sig = Signature.getInstance("SHA1withRSA");
      sig.initVerify(getPublic(keyFile));
      sig.update(data);
  
      return sig.verify(signature);
  }
  
  public void VerifyMessage(String filename, String keyFile) throws Exception 
      {
      try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(filename)))
      {
  
          this.list2 = (List&lt;byte[]&gt;) in.readObject();
      }
  
      lbl13.setText(verifySignature(list2.get(0), list2.get(1), keyFile) ? "VERIFIED MESSAGE" + 
        "\n----------------\n" + new String(list2.get(0)) : "Could not verify the signature.");
  }
  </code></pre>