The current API does not indicate that scala.collection.immutable.List has the Serializable trait:
scala> List(1,2).isInstanceOf[Serializable]res0: Boolean = true
(Forgot to send to scala-user)---------- Forwarded message ----------
From: Brian Maso <brian....@gmail.com>
Date: 2012/1/11
Subject: Re: [scala-user] Why can I serialize scala.collection.immutable.List ?
To: √iktor Ҡlang <viktor...@gmail.com>
2012/1/11 √iktor Ҡlang <viktor...@gmail.com>scala> List(1,2).isInstanceOf[Serializable]res0: Boolean = true
Yes, but
scala> implicitly[List[_] <:< java.io.Serializable]
<console>:8: error: Cannot prove that List[_] <:< java.io.Serializable.
implicitly[List[_] <:< java.io.Serializable]
Which is odd considering
scala> implicitly[::[_] <:< java.io.Serializable]
res2: <:<[scala.collection.immutable.::[_],java.io.Serializable] = <function1>
I'm wondering why the base type wasn't declared Serializable, but instead the two subsclasses are. Just a little odd. Not a big deal.
Thanks Kev, clearest answer of the lot!
There would be no harm that I can see. The utility would be in documenting to people that it is safe to serialize lists.Matthew