Skip to content

Instantly share code, notes, and snippets.

@liptga
Created November 13, 2019 21:22
Show Gist options
  • Save liptga/168262c6fd9e811e43365ff821e9fbb5 to your computer and use it in GitHub Desktop.
Save liptga/168262c6fd9e811e43365ff821e9fbb5 to your computer and use it in GitHub Desktop.
Serialization Puzzle
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