参考资料https://www.cnblogs.com/lanxuezaipiao/p/3369962.html
https://www.liaoxuefeng.com/wiki/1252599548343744/1298366845681698
在java中,只要实现了java.io.Serializable接口,该类就可以序列化。
transient关键字用来标明不想序列化的某个属性,例如在ArrayList源码中,elementData就不想被序列化,则使用了transient。
1 2 3 4 5 6 7 8 9 10
| public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, java.io.Serializable { private static final long serialVersionUID = 8683452581122892189L; private static final int DEFAULT_CAPACITY = 10; private static final Object[] EMPTY_ELEMENTDATA = {}; private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {}; transient Object[] elementData; ... }
|