fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. public class Main {
  9. public static void main(String[] args) throws Exception {
  10. Game game = new Game();
  11. game.name = "seal";
  12. game.email = "seal@";
  13.  
  14.  
  15. Game newGame = game.makeClone();
  16. System.out.println(newGame.email);
  17.  
  18. System.out.println(game.toString());
  19. System.out.println(newGame.toString());
  20. }
  21. }
  22.  
  23. class Game implements Serializable {
  24.  
  25. public String name;
  26. public String email;
  27.  
  28. public Game makeClone() throws IOException, ClassNotFoundException {
  29. ObjectOutputStream out = new ObjectOutputStream(outputStream);
  30. out.writeObject(this);
  31.  
  32. ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
  33. ObjectInputStream in = new ObjectInputStream(inputStream);
  34. Game copied = (Game) in.readObject();
  35. return copied;
  36. }
  37. }
Success #stdin #stdout 0.06s 711168KB
stdin
Standard input is empty
stdout
seal@
Game@a57993
Game@d93b30