I have 2 functions (1 of them is partial) defined similarly under an object:
val partialFn: scala.PartialFunction[String, Int] =
new AbstractPartialFunctio
Because you are explicitly creating AbstractPartialFunction
without extending Serializable
. If you do the same with new AbstractFunction1[String, Int] { ... }
, it also won't be serializable. On the other hand, when you use the anonymous function syntax, the compiler generates a class which does extend Serializable
. This includes anonymous partial function syntax:
scala> val x: PartialFunction[Int, Boolean] = { case 0 => true }
x: PartialFunction[Int,Boolean] = <function1>
scala> x.isInstanceOf[Serializable]
res0: Boolean = true