java序列化时有数组_int序列化java的数组 (Array of int serialization java)

英文原文

Everything here is OK. The devil is in the details, though. It's clear that this isn't the real code, but rather your summary of the code, and so you've accidentally fixed something while summarizing it. The most likely problem you're having is that Java serialization will, by default, only write a given object to a stream once; so if you write an array, change the contents, and write it again, the second instance will come over the wire as just a reference to the first, with the first set of values. Cloning the array in your "packet" constructor, as someone else has mentioned, would definitely help!

中文翻译

这里的一切都还可以。然而,魔鬼在细节中。很明显,这不是真正的代码,而是你对代码的总结,所以你在总结它时偶然修复了一些东西。您遇到的最可能的问题是,Java序列化默认情况下只会将给定对象写入流一次;因此,如果您编写一个数组,更改内容,然后再次写入,第二个实例将作为第一个参考,只有第一个值的参考。像其他人提到的那样,在" 数据包" 构造函数中克隆数组肯定会有所帮助!

Everything here is OK. The devil is in the details, though. It's clear that this isn't the real code, but rather your summary of the code, and so you've accidentally fixed something while summarizing it. The most likely problem you're having is that Java serialization will, by default, only write a given object to a stream once; so if you write an array, change the contents, and write it again, the second instance will come over the wire as just a reference to the first, with the first set of values. Cloning the array in your "packet" constructor, as someone else has mentioned, would definitely help!

这里的一切都还可以。然而,魔鬼在细节中。很明显,这不是真正的代码,而是你对代码的总结,所以你在总结它时偶然修复了一些东西。您遇到的最可能的问题是,Java序列化默认情况下只会将给定对象写入流一次;因此,如果您编写一个数组,更改内容,然后再次写入,第二个实例将作为第一个参考,只有第一个值的参考。像其他人提到的那样,在" 数据包" 构造函数中克隆数组肯定会有所帮助!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值