Java 在LinkedList中序列化是如何工作的?
我不明白LinkedList如何理解反序列化后第一个和最后一个元素的位置。 因为字段具有以下结构Java 在LinkedList中序列化是如何工作的?,java,serialization,linked-list,transient,Java,Serialization,Linked List,Transient,我不明白LinkedList如何理解反序列化后第一个和最后一个元素的位置。 因为字段具有以下结构 /** * Pointer to first node. * Invariant: (first == null && last == null) || * (first.prev == null && first.item != null) */ transient Node<E> first; /** * Pointe
/**
* Pointer to first node.
* Invariant: (first == null && last == null) ||
* (first.prev == null && first.item != null)
*/
transient Node<E> first;
/**
* Pointer to last node.
* Invariant: (first == null && last == null) ||
* (last.next == null && last.item != null)
*/
transient Node<E> last;
/**
*指向第一个节点的指针。
*不变量:(first==null&&last==null)||
*(first.prev==null&&first.item!=null)
*/
瞬变节点优先;
/**
*指向最后一个节点的指针。
*不变量:(first==null&&last==null)||
*(last.next==null&&last.item!=null)
*/
瞬时节点最后;
有人能帮助理解它吗?确定在重建列表过程中第一个和最后一个引用的内容。以下是链接中的代码:
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
// Read in any hidden serialization magic
s.defaultReadObject();
// Read in size
int size = s.readInt();
// Read in all elements in the proper order.
for (int i = 0; i < size; i++)
linkLast((E)s.readObject());
}
可能重复的
void linkLast(E e) {
final Node<E> l = last;
final Node<E> newNode = new Node<>(l, e, null);
last = newNode;
if (l == null)
first = newNode;
else
l.next = newNode;
size++;
modCount++;
}