由于Java LinkedList的所有成员变量都是瞬态的,因此实现Serializable会有什么用? [英] As all the member variables of java LinkedList is transient, what will be the use of implementing Serializable?

查看:157
本文介绍了由于Java LinkedList的所有成员变量都是瞬态的,因此实现Serializable会有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)在LinkedList实现中,所有3个成员的变量大小,第一个,最后一个是瞬态的,那么实现serializable的用途是什么?

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

2)当我们尝试序列化LinkedList时会保留什么?

2) What will be persisted when we try to serialize a LinkedList?

推荐答案

你会注意到 LinkedList writeObject readObject 方法。这些写入/读取列表的大小并写入/读取列表中的每个对象。

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.

这篇关于由于Java LinkedList的所有成员变量都是瞬态的,因此实现Serializable会有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆