As all the member variables of java LinkedList is transient, what will be the use of implementing Serializable?

后端 未结 2 509
猫巷女王i
猫巷女王i 2020-12-19 10:31

1) In LinkedList implementation all the 3 member varaibles size, first, last are transient, then what is the use of implementing serializable?

2) What will be persi

相关标签:
2条回答
  • 2020-12-19 11:14

    Have a look at readObject() and writeObject(). It will serialize entreis of the List not the list itself, and reconstructs it from the entries.

    0 讨论(0)
  • 2020-12-19 11:15

    You'll notice LinkedList has writeObject and readObject methods. These write/read the size of the list and write/read each object in the list.

    Note that these methods (but also the fields) are private so the implementation may change. Don't depend on it. Depend on the interfaces.

    0 讨论(0)
提交回复
热议问题