JAva IO ObjectInputStreamオブジェクトのシーケンス化と逆シーケンス化そしてシーケンス化インタフェースSerializableの役割


import java.io.*;
class Person implements Serializable
{
    String name;
    int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
public class Main {

    public static void main(String[] args) throws IOException, ClassNotFoundException {


        //                 
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("/Users/mac/java/obj.object"));
        //          Serializable        
        // Serializable                serizlVersionUID                
        //                              
        oos.writeObject(new Person("    ",12));
        oos.close();


        ObjectInputStream ois=new ObjectInputStream(new FileInputStream("/Users/mac/java/obj.object"));
        Person p=(Person)ois.readObject();
        System.out.println(p.getName()+" "+p.getAge());

    }
}



ここで注目すべきは静的およびtransientは ObjectInputStreamファイルに書き込まれた