2013年9月16日星期一

About Serializable, Why implement Serializable be able to achieve serialization

 This post last edited by the kolnick on 2013-09-16 10:07:49
Why implement Serializable serial number can be achieved , I look inside source Serializable interface does not define any methods
seeking guidance
------ Solution ---------------------------------- ----------
it is a marker interface .
------ Solution ---------------------------------------- ----
serialization is a historical problem , it can be said that design flaws in Java world.

" Why implement Serializable serialization can be achieved ."

simple answer is the key ObjectInputStream and ObjectOutputStream method will serialize the Object you want to do the inspection, the type must be Serializable.

correct sequence of design work to be done is definitely more than just add implements Serializable so simple.
------ Solution ---------------------------------------- ----
serialization implementation: will need to be serialized class implements serializable interface, which does not need to implement the method , implements Serializable just to mark the object is being serialized , and then use an output streams ( such as : FileOutputStream) to construct a ObjectOutputStream ( object stream ) object , then use ObjectOutputStream object writeObject (Object obj) method can be an object obj parameter write ( ie save its state ) , to restore if the input stream .
------ For reference only -------------------------------------- -


seeking Detailed
------ For reference only ------------------------------ ---------

  Detailed requirements
 

Chapter 11 "Serialization"

没有评论:

发表评论