Java hashset how to serialise multiple objects

前端 未结 1 592
太阳男子
太阳男子 2021-01-29 07:15

I asked a previous question about how I would save multiple save files to a .ser file, and I was suggested to use a hashset because they are serializable. I have tried to write

相关标签:
1条回答
  • 2021-01-29 07:27

    Solution: Serialize the hashset itself. Just make sure testClass implements Serializable and all of its fields do so to.

    When you want to unserialize it and read the object, you cast it to HashSet<testClass> and it will maintain its state as before you serialized it.

    0 讨论(0)
提交回复
热议问题