gpt4 book ai didi

java - Guava 不可变集合的序列化是否稳定?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:12:28 48 4
gpt4 key购买 nike

有人警告我不要在序列化通信中使用的对象中使用 Guava 不可变集合,因为如果更新了 Guava 的一端版本,可能会出现序列化版本不兼容的问题。这是一个合理的担忧吗?

最佳答案

让我们给出一些观点。

序列化最突出的用途是:

  1. 在应用程序运行之间存储数据
  2. 在客户端和服务器之间发送数据

如果您控制在客户端和服务器上使用的 Guava 版本,Guava 完全适合应用程序 2。此外,虽然 Guava 不保证 Guava 版本之间序列化的一致性......实际上,序列化形式不会经常更改。

另一方面,让我谈谈为什么 Guava 不保证序列化表单的一致性。我在 Guava 版本 9 和 10 之间更改了 ImmutableMultiset 的序列化形式,原因是我需要重构一些东西,以便我可以将 ImmutableSortedMultiset 添加到不可变集合中。你可以自己看看变化here .试图在保持序列化形式一致的同时进行同样的重构几乎肯定需要额外的笨拙的黑客攻击,这……非常违背 Guava 团队的理念。 (这可能是由比我更专业的程序员来完成的,但我仍然声称这不是微不足道的。)长期保证序列化兼容性需要付出惊人的努力,如 above linked mailing list thread 中所讨论的那样。 ,凯文说:

Trying to provide for cross-version compatibility made things a hundred times more difficult and we gave up on it before Guava even started.

和贾里德:

The underlying problem is still there: ensuring that the serialized forms are compatible between all Guava versions. That was a goal of mine when working towards Google Collections 1.0, but I abandoned that goal after realizing its difficulty. Implementing and testing cross-version compatibility wasn't worth the effort.

最后,我要指出的是,Guava 在 Google 内部得到广泛使用并且管理得很好。

关于java - Guava 不可变集合的序列化是否稳定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8314318/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com