Java object serialization requires the implementation of a Serializable interface, but the implementation of another interface also works, called Externalizable.
Only non-static member variables are serialized. If a referenced variable exists, the referenced variable must also implement the interface.
If you do not want to serialize a member variable, add the keyword transient before it.
If you want to operate serialization, serialize some members, or serialize some Members, you can complete serialization in your own class.
Write down the following method
Private void writeObject (java. io. ObjectOutputStream oos) throws IOException
{
}
Private void readObject (java. io. ObjectOutputStream oos) throws IOException
{
}
These two methods will be called during serialization. Www.2cto.com
These two methods are private. It is reasonable to say that they can only be called in the class. How can they be called outside the class?
Author: zhy_cheng