title: ClassCastException when reading from binary file
body: <p>I get a <code>java.lang.ClassCastException</code> while reading a binary file with a generic method.
  I was trying to read two diferent files with the same method but then I get the exception and I dont know why.</p>
  
  <p>This is the code in the method generic for read the file:
  <code>Read</code> is a method part of the Class <code>ReadBenary</code>.</p>
  
  <pre><code> import java.io.ObjectInputStream;
   import java.io.FileInputStream;
   import java.io.IOException;
  
   public class ReadBinary{
  
  private ObjectInputStream reader;
  
  public boolean open(String name) {
      try {
          reader= new ObjectInputStream(new FileInputStream(name));
          return true;
      } catch (IOException exception) {
          System.err.println("Error");
          return false;
      }
  }
  
  public void close() {
      try {
          if (reader != null) {
              lector.close();
          }
      } catch (IOException exception) {
          System.err.println("Error");
      }
  }
  
  public &lt;E&gt; E read() {
  
      E object = null;
      try {
          object = (E) reader.readObject();
      } catch (ClassNotFoundException ex) {
          System.err.println("Class dont found");
          System.err.println(ex);
      } catch (IOException ex) {
          System.err.println("End of the file");
          System.err.println(ex);
      } catch (ClassCastException ex) {
          System.err.println("Class dont found");
      }
      return object;
  }
  </code></pre>
  
  <p>This is the code in the main:</p>
  
  <pre><code> ReadBinary reader= new ReadBinary();
  
        if (reader.open(file3)) {
        *  Bill bill = reader.read();
          while (bill != null) {
              manejadorBill.insert(bill);
              bill = reader.read();
          }
          reader.close();
         }
  
      if (reader.open(file1)) {
          Customer customer= reader.read();
          while (customer != null) {
              manejadorCustomer.insert(customer);
              customer = reader.read();
          }
          reader.close();
      }
  </code></pre>
  
  <p>This is the method that write the objects in the file:</p>
  
  <pre><code>public &lt;E&gt; void escribir(E objeto) {
      try {
          escritor.writeObject(objeto);
      } catch (IOException exception) {
          System.err.print("Error rawr");
      }
  }
  </code></pre>
  
  <p><code>Bill</code> and <code>Customer</code> are two independent class.
  When i try to run the program it says that <code>Customer</code> cant be cast as <code>Bill</code>.</p>
  
  <p>It says that the error occurs in the line with *. </p>