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
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.