Why does ArrayList use transient storage?

前端 未结 6 1256
既然无缘
既然无缘 2020-12-24 05:55

I was reading the source of Java\'s ArrayList and I came across its backing array declaration:

private transient Object[] elementData;

Why

6条回答
  •  [愿得一人]
    2020-12-24 06:40

    ArrayList implements Serializable, so it can be serialized, that's exactly why the private backing array is transient, so it is not serialized along with other data in the class, since all is handled by ArrayList's writeObject and readObject methods.

提交回复
热议问题