How to serialize a lambda?

后端 未结 5 820
眼角桃花
眼角桃花 2020-11-22 08:29

How can I elegantly serialize a lambda?

For example, the code below throws a NotSerializableException. How can I fix it without creating a Seriali

5条回答
  •  死守一世寂寞
    2020-11-22 09:20

    If you are willing to switch to another serialization framework like Kryo, you can get rid of the multiple bounds or the requirement that the implemented interface must implement Serializable. The approach is to

    1. Modify the InnerClassLambdaMetafactory to always generate the code required for serialization
    2. Directly call the LambdaMetaFactory during deserialization

    For details and code see this blog post

提交回复
热议问题