Serializing a priority queue in scala

后端 未结 1 754
清酒与你
清酒与你 2021-01-23 15:08

I am trying to serialize a mutable PriorityQueue in scala (2.10) and am getting a NotSerializableException when writing the object to an ObjectOutputSt

1条回答
  •  走了就别回头了
    2021-01-23 15:44

    This should be reported as a bug - the fix is to simply make the nested ResizableArrayAccess class inherit Serializable.

    Technically, maybe you could use reflection to remove the private and final modifiers on the resarr field in the priority queue class, then set it to null before serialization.

    Otherwise, converting the priority queue to a, say, array before serialization and vice versa on deserialization would avoid this exception. You could roll in your own wrapper around the PriorityQueue to implement custom serialization/deserialization.

    Note: This issue has been resolved in Scala 2.11.0-M7 (SI-7568)

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