Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boolean is not Serializable?

Consider this tiny snippet:

scala> val u = true.asInstanceOf[Serializable]
java.lang.ClassCastException: java.lang.Boolean cannot be cast to scala.Serializable

Well that is a bit of a surprise.. The motivation is to support a modest range of classes - both primitives and custom classes (which do explicitly `extends Serializable).

So then what is the way to handle automatic serialization of these primitives?

like image 394
WestCoastProjects Avatar asked Jan 06 '23 02:01

WestCoastProjects


1 Answers

java.lang.Boolean is not scala.Serializable. It is however java.io.Serializable:

scala> val u = true.asInstanceOf[java.io.Serializable]
u: java.io.Serializable = true

See http://www.scala-lang.org/api/2.11.8/#scala.Serializable for information about scala.Serializable which seem to indicate some kind of cross platform serialization between JVM and .NET.

like image 190
thoredge Avatar answered Jan 15 '23 06:01

thoredge