Externalizable和Serializable

Externalizable和Serializable

java.io

Interface Serializable 可序列化的

java.io

Interface Externalizable 可外部化的

Externalizable里面有两个方法

void readExternal(ObjectInput in)
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.
void writeExternal(ObjectOutput out)
The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

可以自己控制序列化的过程。

Serializable里面没有方法,标记实现Serializable的类是可以被序列化的。

java编译其自动帮你实现序列化。

推荐使用Serializable。

 

猜你喜欢

转载自mfcfine.iteye.com/blog/2385104