英文原文
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序列化默认情况下只会将给定对象写入流一次;因此,如果您编写一个数组,更改内容,然后再次写入,第二个实例将作为第一个参考,只有第一个值的参考。像其他人提到的那样,在" 数据包" 构造函数中克隆数组肯定会有所帮助!