Is it possible to serialize anonymous class without outer class?

前端 未结 6 982
广开言路
广开言路 2021-02-06 03:45

I made a small research on web and reviewed related topics on this site, but the answers were contradictory: some people said it is not possible, others said it is possible, but

6条回答
  •  清歌不尽
    2021-02-06 04:07

    I'd like to add to this topic. There is a way to achieve what you want, but will require reflection.

    Here is a good tutorial on implementing a custom serializable object using writeObject and readObject

    And here is a good tutorial (website font is kind of an eyesore, but the content is worth it) on on how Reflection is used to for serialization. The tutorial refers to final fields, but applies to any field.

    You'll have to use Reflections getDeclaredField

提交回复
热议问题