Created
November 13, 2019 21:22
-
-
Save liptga/168262c6fd9e811e43365ff821e9fbb5 to your computer and use it in GitHub Desktop.
Serialization Puzzle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.util.SerializationUtils; | |
import java.io.Serializable; | |
public class SerializationPuzzle { | |
public static void main(String[] args) { | |
B deserialized = (B) SerializationUtils.deserialize( | |
SerializationUtils.serialize(new B("alma"))); | |
System.out.println(deserialized.getText()); | |
} | |
public static class A { | |
private final String text; | |
public A(String text) { | |
this.text = text; | |
} | |
public String getText() { | |
return text; | |
} | |
} | |
public static class B extends A implements Serializable { | |
public B(String text) { | |
super(text); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment