为什么将Hashtable的table属性序列化? [英] Why is the table attribute of Hashtable serialized?

查看:107
本文介绍了为什么将Hashtable的table属性序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Hashtabletable字段被序列化了,尽管它被标记为transient?

Why is the table field of Hashtable serialized, although it is marked as transient?

推荐答案

它被标记为瞬态的,因为在Entry数组上使用默认的序列化方案是不安全的.相反,当对哈希表进行反序列化时,必须重新哈希表中的键,并且必须根据新的哈希码值将条目添加到插槽中.这是必要的,因为在进行反序列化之后,密钥可能具有不同的哈希码……出于各种原因.这项工作将通过Hashtable的readObject()方法完成.

It is marked as transient because it is unsafe to use the default serialization scheme on the Entry array. Rather, when a Hashtable is deserialized, the keys in the table must be rehashed and the entries must be added to slots according to the new hashcode values. This is necessary because the keys may have different hashcodes after deserialization ... for a variety of reasons. This work will be done by Hashtable's readObject() method.

这篇关于为什么将Hashtable的table属性序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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