Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package t1;
- import java.io.ByteArrayInputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- public class SerCtor {
- static class A{
- A(){
- System.out.println("A: "+System.currentTimeMillis());
- }
- }
- static class B extends A implements java.io.Serializable{
- final int n;
- B(int n){
- this.n = n;
- System.out.println("B: "+System.currentTimeMillis());
- }
- }
- public static void main(String[] args) throws Throwable{
- B b = new B(11);
- System.out.println("B: "+b.n);
- ByteArrayOutputStream buf = new ByteArrayOutputStream();
- ObjectOutputStream out =new ObjectOutputStream(buf);
- out.writeObject(b);
- out.close();
- System.out.println("deserialize");
- ObjectInputStream in =new ObjectInputStream(new ByteArrayInputStream( buf.toByteArray()));
- b = (B) in.readObject();
- in.close();
- System.out.println("B: "+b.n);
- }
- }
- /*
- Output, something like:
- A: 1414349969582
- B: 1414349969582
- B: 11
- deserialize
- A: 1414349969595
- B: 11
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement