title: Class not serializable exception when creatin an inner class in java
body: <p>My code is similar to this thread.
  <a href="https://stackoverflow.com/questions/6662529/class-not-serializable-after-methods-are-overridden?newreg=89e2c3fc5b4541b6ad23d7a76ae54b62">Class not serializable after methods are overridden</a></p>
  
  <p>But my goal is to send a method to be processed on another computer.
  So, i created this class which exists on both ends. When i'm about to serialize the class, i override the method just as shown in above thread, i get the non serializable exception.
  I saw in the above thread that i must create a static inner class. How can i do this?! An anonymus inner class cant be static!
  And if i explicit the class name, i'll have a problem on the de-serialization end of the application.</p>
  
  <p>Client Code:</p>
  
  <pre><code>public static void main(String[] args) {
      try {
          // TODO code application logic here
          Socket client = new Socket("192.168.25.22", 62222);
          System.out.println("Cliente conectado");
          ObjectInputStream input = new ObjectInputStream(client.getInputStream());
          BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
          try { 
              Task t =(Task) input.readUnshared();
              System.out.println("Objeto recebido...");
              t.myTask();
              System.out.println("ok");
          } catch (ClassNotFoundException ex) {
  
              ex.printStackTrace();
          }
      } catch (Exception ex) {
          System.out.println("ERRO!");
          ex.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Server Code:</p>
  
  <pre><code>public static void main(String args[]) {
  
              try {
                  ServerSocket server = new ServerSocket(62222);
                  System.out.println("Listening on 62222...");
  
                  Socket client = server.accept();
                  System.out.println("New client connected with IP: " + client.getInetAddress().getHostAddress());
  
                   Task t = new Task(null){@Override public void myTask(){System.out.println("Olá");}};
  
  
                 //Task tz = new Tsk(null);
  
                  ObjectOutputStream output;
                  output = new ObjectOutputStream(client.getOutputStream());
                  output.writeUnshared(t);
                  output.close();
  
                  System.out.println("Task created");
                  System.out.println("Objeto enviado.");
  
              } catch (Exception ex) {
                  ex.printStackTrace();
              }
  
  
  }
  </code></pre>
  
  <p>Task Class Code:</p>
  
  <pre><code> public class Task implements Serializable{
   List&lt;Object&gt; dataImput;
   List&lt;Object&gt; dataOutput;
   boolean finished;
   private static final long serialVersionUID = 595012310163575L;
  
   public Task(List&lt;Object&gt; dataImput){
       this.finished=false;
       this.dataImput= dataImput;
  
   }
  
   public void myTask(){
       System.out.println("Not Implemented.");
   }
  
  public boolean isFinished() {
      return finished;
  }
  </code></pre>
  
  <p>}</p>