Difference when serializing a lazy val with or without @transient

后端 未结 1 732
离开以前
离开以前 2021-02-01 18:46

Working on spark, sometimes I need to send a non-serializable object in each task.

A common pattern is @transient lazy val, e.g

class A(val          


        
1条回答
  •  一生所求
    2021-02-01 19:26

    see here - http://fdahms.com/2015/10/14/scala-and-the-transient-lazy-val-pattern/

    In Scala lazy val denotes a field that will only be calculated once it is accessed for the first time and is then stored for future reference. With @transient on the other hand one can denote a field that shall not be serialized.

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