Search code examples
scalacollectionsabstractserializable

What is the most general Serializable collection?


AFAIK, GenTraversableOnce is the most general collection type, so I should prefer it over more specific collection types in APIs. However, I don't think is a subtype of Serializable.

If I have

case class(name: String, items: TYPE) extends Serializable

what should TYPE be in order to be the most general?


Solution

  • AFAIK, only concrete classes like List extend Serializable in the collections API. However, you can use the compound type GenTraversableOnce[_] with Serializable:

    case class(name: String, items: GenTraversableOnce[_] with Serializable) extends Serializable