After looking at the source code for some of the Java Collection classes, I found that member variables always change with transient.
For example, the source code LinkedList:
public class LinkedList<E> extends AbstractSequentialList<E> implements List<E>, Deque<E>, Cloneable, java.io.Serializable
{
private transient Entry<E> header = new Entry<E>(null, null, null);
private transient int size = 0;
public LinkedList()
{
header.next = header.previous = header;
}
public LinkedList(Collection<? extends E> c) {
this();
addAll(c);
}
}
Of course, not only does it LinkedListuse the transient, almost all Java collection classes use transientat least half of their member variables to change.
So my question is: why transientused so widely in the standard Java library?
(Of course, everyone knows the definition and use transient, but this is not my question :)
source
share